Code Monkey home page Code Monkey logo

Comments (11)

Zaid-Ajaj avatar Zaid-Ajaj commented on June 13, 2024 1

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.

Zaid-Ajaj avatar Zaid-Ajaj commented on June 13, 2024 1

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.

Numpsy avatar Numpsy commented on June 13, 2024

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.

Zaid-Ajaj avatar Zaid-Ajaj commented on June 13, 2024

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.

Numpsy avatar Numpsy commented on June 13, 2024

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.

Zaid-Ajaj avatar Zaid-Ajaj commented on June 13, 2024

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.

Zaid-Ajaj avatar Zaid-Ajaj commented on June 13, 2024

More complicated schemas are also welcome for testing :)

from hawaii.

Numpsy avatar Numpsy commented on June 13, 2024

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.

Zaid-Ajaj avatar Zaid-Ajaj commented on June 13, 2024

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.

Numpsy avatar Numpsy commented on June 13, 2024

Ah ok.

NSwag will sometimes generate single case oneOf cases like

https://github.com/Numpsy/OpenApiExample/blob/5cd12fc5803bb721c5dccd1795aa414bba02b5ff/generated/OpenApiExample.NSwag.json#L154

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.

Zaid-Ajaj avatar Zaid-Ajaj commented on June 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.