Comments (14)
@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.
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.
Fixed a minor issue, will release the 0.7.0 version today.
from openapi-typescript-codegen.
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.
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.
i have some use cases, but it's always great to have some real-world test data.
from openapi-typescript-codegen.
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.
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.
+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.
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.
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.
@thetrime Sure! sounds like a great idea!
from openapi-typescript-codegen.
Ok, see #399
from openapi-typescript-codegen.
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)
- Unable to run when redocly is installed HOT 2
- Option to rename `requestBody` HOT 1
- Select/Filter Tags to generate specific Services only HOT 1
- Literal fields are converted to optional any HOT 5
- Adding the option to remove certain or all file headers. HOT 1
- Referenced nullable object types are not generated as possibly null HOT 4
- anyOf combining literals and objects generates incorrect code HOT 6
- Ability to process multiple input files HOT 5
- all Of -> $reference. HOT 3
- If all parameters are optional, make the top level object optional too HOT 4
- Generated type definitions should not include the error case HOT 3
- Relative path seems to be based on the node_modules directory and not the cwd HOT 3
- Support for Server Side Event HOT 3
- Wrong path on Windows HOT 16
- Unable to recognize the "openAPI" entry as the name of a Cmdlet, function, script file, or executable program. Please check the spelling of the name, if it includes Path, please make sure the path is correct and try again. HOT 7
- Error 'unknown option '--name' when using openapi-typescript-codegen version '0.13.0' HOT 1
- oneof enum generates incorrect code HOT 11
- Update sendRequest for axios to align on parameter deprecation (withCredentials) HOT 7
- [READ THIS!] This repository is not being maintained anymore. Use nicolas-chaulet/openapi-typescript-codegen instead! HOT 8
- 'fetch is not defined\n' 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-typescript-codegen.