Code Monkey home page Code Monkey logo

Comments (14)

ferdikoomen avatar ferdikoomen commented on May 18, 2024 4

@artem-tim I investigated the issue and started to make some changes. I need to call it a day now, but i will ping you when there is a working branch. Keep you posted.

from openapi-typescript-codegen.

ferdikoomen avatar ferdikoomen commented on May 18, 2024 1

Hi @artem-tim i have some other changes pending as well, like the support for response header parsing. Let me check if i can fit this in. Might have some time over the weekend to update this. Thanks for the info, this should help a lot.

from openapi-typescript-codegen.

ferdikoomen avatar ferdikoomen commented on May 18, 2024 1

Fixed a minor issue, will release the 0.7.0 version today.

from openapi-typescript-codegen.

kcappieg avatar kcappieg commented on May 18, 2024

It seems "anyOf" is not supported in any model. A couple code files are depending on the type definition to be a string, not an array of strings. (First error was thrown to me in file ...dist/openApi/v3/parser/stripNamespace.js. I monkey-patched the first error to see if I could get the whole thing working, but then got another error somewhere further down the chain.)

Seems like a useful project, hope you keep working on it.

UPDATE: Forgot to leave version number. I installed via npm, so version 0.2.7.

from openapi-typescript-codegen.

ferdikoomen avatar ferdikoomen commented on May 18, 2024

Hey @kcappieg Would it be possible to send me your spec file (in an email or dm). I can have a quick look to see what needs to happen. Im always happy to support the full OpenAPI spec.

from openapi-typescript-codegen.

ferdikoomen avatar ferdikoomen commented on May 18, 2024

i have some use cases, but it's always great to have some real-world test data.

from openapi-typescript-codegen.

kcappieg avatar kcappieg commented on May 18, 2024

Turns out I misunderstood something about the openapi spec. I'm new to OpenAPI and using Stoplight as a GUI editor. When building models, it allows you to specify multiple types that it outputs as an array in the JSON OpenAPI spec. This seems to be the same as anyOf, but a different syntax. Reviewing the docs from swagger.io... this does not actually seem like it's valid syntax :(

So instead of

"myModel": {
  "anyOf": [/*some types*/]
}

It outputs:

"myModel": {
  "type": ["string","integer"]
}

The dangers of trusting a GUI to do the heavy lifting for you...

Thanks for the response, but it seems I need to better understand the spec before I can complain something's not working!

from openapi-typescript-codegen.

artem-tim avatar artem-tim commented on May 18, 2024

Hi, hopping onto the issue - we are also considering to use this (instead of that awful java codegen) for our project, but we would need the support for anyOf/oneOf as well
The spec is here https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/
Basically instead of only being able to have a single schema :

      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Animal'

We would have a possibility to allow several possible inputs for the API :

      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'

However the spec allows oneOf etc at multiple levels, even within the schema itself (it should be possible to replace 1 object by an oneOf array of sub-objects)

Right now, the generated code with a requestBody using anyOf/oneOf creates a malformed output :

    public static async postAuthenticationService3(
        requestBody: ,
    ): Promise<any> {

To demonstrate our usecase : the schema is like this (json) : (in this example this is a password reset API that should handle both the token request (input : email), or to submit a changed password using input a valid token with new password)

            "requestBody":{
               "required":true,
               "description":"",
               "content":{
                  "application/json":{
                     "schema":{
                        "oneOf":[
                           {
                              "type":"object",
                              "properties":{
                                 "email":{
                                    "type":"string",
                                    "default":"",
                                    "example":"",
                                    "description":"E-mail"
                                 }
                              },
                              "required":[
                                 "email"
                              ],
                              "additionalProperties":false
                           },
                           {
                              "type":"object",
                              "properties":{
                                 "token":{
                                    "type":"string",
                                    "default":"",
                                    "example":"",
                                    "description":"Token"
                                 },
                                 "temp_pwd":{
                                    "type":"string",
                                    "format":"password",
                                    "default":"",
                                    "example":"",
                                    "description":"Temporary Password"
                                 },
                                 "password":{
                                    "type":"string",
                                    "format":"password",
                                    "default":"",
                                    "example":"",
                                    "description":"New Password"
                                 }
                              },
                              "required":[
                                 "token",
                                 "temp_pwd",
                                 "password"
                              ],
                              "additionalProperties":false
                           }
                        ]
                     },
                     "examples":{
                        "Send_Email":{
                           "value":{
                              "email":"my@email"
                           }
                        },
                        "Update_Password":{
                           "value":{
                              "token":"<my_password_reset_token>",
                              "temp_pwd":"<my_temporary_password>",
                              "password":"<my_new_password>"
                           }
                        }
                     }
                  }
               }
            }

Do you think the support for oneOf/anyOf and such could be added ? I don't mind contributing if there is not enough bandwidth

from openapi-typescript-codegen.

patrikniebur avatar patrikniebur commented on May 18, 2024

+1 on this. Great project, thank you for doing this. Would like to use it in our workflow too but need support for allOf and oneOf

from openapi-typescript-codegen.

thetrime avatar thetrime commented on May 18, 2024

I've noticed that https://github.com/diverta/kuroco-sdk/blob/master/src/generator/openApi/v3/parser/getModel.ts implements this, though it's not completely clear that this was the first project to do so. Patching it in to this repo gives me the results I'd expect to see (though I had to also add es2019 to the lib section of tsconfig.json so I could get things like Array.flat). I'll see if I can track down the original implementor...

from openapi-typescript-codegen.

thetrime avatar thetrime commented on May 18, 2024

It looks like diverta really did come up with that change first. Are you interested in a PR if I tidy it up to keep it ES2017?

from openapi-typescript-codegen.

ferdikoomen avatar ferdikoomen commented on May 18, 2024

@thetrime Sure! sounds like a great idea!

from openapi-typescript-codegen.

thetrime avatar thetrime commented on May 18, 2024

Ok, see #399

from openapi-typescript-codegen.

ferdikoomen avatar ferdikoomen commented on May 18, 2024

Pushed 0.7.0-beta to NPM, thanks everybody for the input and specially @budde377 for the PR. Lets test the changes and see if they are working well.

from openapi-typescript-codegen.

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.