Giter Site home page Giter Site logo

Comments (4)

spacether avatar spacether commented on June 29, 2024

The code generation is functioning as expected here. The anyOf refs are not known as possible types. For them to be known they would have to be examined at one higher schema level and compared against type info. Currently the generation only knows about input and output types for array and object, types defined in type, and ref only. Because anyOf is not analyzed for type info, the only info comes from absent type info which allows any type.

If you want different functionality here, please consider filing a PR with thorough test cases.

from openapi-json-schema-generator.

spacether avatar spacether commented on June 29, 2024

Also, should your anyOf be a oneOf so it matches only one of those schemas rather than one or more?

from openapi-json-schema-generator.

Marcelo00 avatar Marcelo00 commented on June 29, 2024

Thanks for the information. Is it possible to have a short meeting or could you point out the necessary steps for such functionality? We would like to invest some time to add such feature as our use case prefers to work with these classes and it would be nice to have proper type hints. However, we cannot really judge how long it may take.

I would also assume that this behavior also occurs with other modifiers like oneOf. Is it correct?

Also, should your anyOf be a oneOf so it matches only one of those schemas rather than one or more?

You are right. Our openAPI.yaml is also auto-generated which sometime causes semantically wrong specification like this.

from openapi-json-schema-generator.

spacether avatar spacether commented on June 29, 2024

Adding this is non-trivial.
In the latest version of the generators, returned instances only subclass one class. So to do this one would need to:

  • perhaps generate interfaces for all object types and have the object output classes implement them
  • accumulate type + interface/dict output class info from all subschemas
  • for use cases like this, the code will know from introspecting the calculated type constraints that only dicts are allowed. And we know that the oneOf interfaces or output types are allowed

Doing this is difficult because any number of keywords can exist in the same schema including:

  • type
  • oneOf
  • allOf
    etc and type and interface information need to be gathered from them and correctly combined

So a new CodegenSchema field that could store this may look like typeToInterfaces: Map<String, List>
Interfaces can come from refed locations so one would need to store the ref location and the name of the generated interface class. Some examples:
typeToInterfaces = {"string": null, "boolean": null} # fora a schema that allows strings and numbers
typeToInterfaces = {"object": [{SingleValueClassificationAttributeInterface, MultiValueClassificationAttributeInterface}]} # for your use case with oneOf two object types
This property would need to be added to CodegenSchema.

When are you free to discuss this this week and next week?

from openapi-json-schema-generator.

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.