Comments (4)
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.
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.
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.
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)
- Java client, adds missing 3.1.0 schema validators HOT 1
- Java client, integrate servers into api configuration
- Java client, create component security schemes HOT 1
- Java client integrate component security schemes into ApiConfiguration
- [Announcement] 2024 Project Ideas HOT 1
- Java client, add requestBody feature
- Java client: add Response Object
- Java client: add Responses
- Java client, add header + serialization implementation
- [BUG] Error transforming enum values beginning with numbers HOT 1
- [REQ] add OAuth2SecurityScheme with the password flow HOT 1
- Java client, add operation
- [BUG][python] Missing quotes for array property in TypedDict definition HOT 2
- [BUG][python] Reference Error when using schema with optional properties HOT 2
- [BUG][python] Validation for nullable property HOT 3
- [REQ][python] Allow type: number format: float to ingest json integers HOT 7
- [REQ] Allow Content Type JSON Lines HOT 12
- [BUG] Build failure on java 17 and 21 HOT 1
- [BUG][python] Crash when generating const property HOT 2
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 openapi-json-schema-generator.