Comments (11)
Hi @Numpsy this should be an easy fix I think. We can split the description over multiple lines.
It would be awesome if you could share the schema you have or an anonymised version of it where you rename fields or remove descriptions. It would make for a good example to test this project with since I don't have proper sNSwag schema's to work with.
from hawaii.
Hi @Numpsy as of latest source, enum types (with enum names), enum flags (without names) and allOf
references are handled (for inheritance). Please give it a try and see if I missed something other than oneOf
and the client generation
from hawaii.
fwiw, those 'multi line' descriptions appear to be created in the same way by Swashbuckle to, so not NSwag specific (Those are the only two libs i've tried using to generate schemas from a service, so I can't comment on other languages).
I'll have a look at what I can do with the schema (or maybe see about creating a sample project with functions of a similar shape) - I was thinking of adding some thoughts\samples on integer enums or the way it can use allOf
to describe inheritance (neither of which) appear to be rendered in the set of types generated by the current source)
from hawaii.
As for allOf and anyOf, I am aware of this problem and will tackle it soon, already setting up a specialized JSON converter to be generated types alongside the client project.
Will be looking forward to your samples schemas 🙏
from hawaii.
fwiw, I put a couple of (very) simple schemas at https://github.com/Numpsy/OpenApiExample/tree/default/generated that show how Swashbuckle and NSwag use a differing approach to allOf for subtypes (NSwag includes base/subtypes in the schema by default, where Swashbuckle merges everything into one object unless configured otherwise.), and also shows a bit of extra metadata that NSwag includes for enums that it's own client generator uses (which may or may not be of interest).
I was going to include an example TimeSpan property in the models as well as that's an extra little bit of 'fun' with ASP.Net Core, but then just kept it simple.
from hawaii.
Thanks a lot for the example schemas 🙏 I think I can make the integer enums work with the generator. As for allOf
, I think merging the properties will be the best approach by default since F# records don't like inheritance
from hawaii.
More complicated schemas are also welcome for testing :)
from hawaii.
I had a go earlier, and the integer enum types were generated, and derived classes looked to contain the full set of properties.
By oneOf
do you mean the way that properties defined with oneOf in the schema are typed as string
in the generated records rather than the referenced type?
from hawaii.
By one of I mean the way by which OpenAPI describes that something is one of multiple types such as Foo or Bar which ideally should be turned into discriminated unions of each case but I am not there yet
from hawaii.
Ah ok.
NSwag will sometimes generate single case oneOf
cases like
So my previous comment was referring to a case I saw where the schema is something like
"PostRequest": {
"type": "object",
"additionalProperties": false,
"properties": {
"requestFlags": {
"$ref": "#/components/schemas/FlagsEnum"
},
"someThing": {
"nullable": true,
"oneOf": [
{
"$ref": "#/components/schemas/Thing"
}
]
}
}
}
and Hawaii generated
type PostRequest =
{ requestFlags: Option<FlagsEnum>
someThing: Option<string> }
///Creates an instance of PostRequest with all optional fields initialized to None. The required fields are parameters of this function
static member Create (): PostRequest =
{ requestFlags = None
someThing = None }
rather than Option<Thing>
(no need for a union when there is only one type).
I think the reason it generates schemas like that might be because you aren't supposed to have a $ref
with other properties attached so it works around the issue by nesting things?
(though saying that, I believe NSwags own client generator has limitations with oneOf for reasons including C# not doing discriminated unions as nicely you'd be able to do it in F#)
from hawaii.
Yeah oneOf with a single type is just that type. The reason you are getting Option is because I haven't implemented what the generator should do ;) it is good to know that we are close to the limitations of NSwag in terms of type codegen. I will be implementing the client soonish
from hawaii.
Related Issues (20)
- Any way to incorporate binary streams? HOT 1
- Support for TimeSpan types in responses? HOT 2
- return values not included HOT 5
- Urls containing [ and ] generates code that does not compile HOT 7
- API:s requiring credentials fail HOT 3
- Add capability to also generate Openapi spec file from F# project? HOT 2
- System.NullReferenceException on Homebridge schema HOT 3
- Paths level Parameters are ignored HOT 6
- uuid response type as string and not converted to Guid HOT 2
- Header Parameter HOT 3
- Response Header Parameter HOT 1
- Hawaii throws: Unhandled exception. Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: D. Path '', line 0, position 0. HOT 6
- Generation of nullable required property HOT 1
- Improper management of connection errors HOT 5
- Use Templatus for F# code generation HOT 4
- Throws StackOverflowException HOT 4
- Wrong version is printed when calling hawaii --version HOT 1
- Nullable types in Dictionary values don't seem to be treated as plain Nullable values HOT 4
- Make possible to pass a cancellation token HOT 1
- Multiple client request parameters as a record
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hawaii.