Swagger parser#30
Conversation
| } | ||
|
|
||
| /** | ||
| * Parses a Hydra documentation and converts it to an intermediate representation. |
There was a problem hiding this comment.
On a quick scan i noticed this mentions Hydra, should be swagger i expect.
… into swagger-parser
|
I think now it's OK. Can you guys make a review? |
dunglas
left a comment
There was a problem hiding this comment.
Awesome! Thank you very much for working on this. It's definitely something we want in.
| import Field from "../Field"; | ||
| import Resource from "../Resource"; | ||
|
|
||
| String.prototype.capitalize = function() { |
There was a problem hiding this comment.
It's confusing because it doesn't do the same thing than underscore/lodash capitalize.
Can you use _.upperFirst() instead of adding new functions to the global String prototype? We already use lodash in the project: https://github.com/api-platform/api-doc-parser/blob/master/package.json#L39
| export default function(response, entrypointUrl) { | ||
| const paths = Object.keys(response.paths) | ||
| .map(item => item.replace(`/{id}`, ``)) | ||
| .filter(onlyUnique); |
There was a problem hiding this comment.
Can be replaced by https://lodash.com/docs/4.17.10#uniq
| const fields = fieldNames.map( | ||
| fieldName => | ||
| new Field(fieldName, { | ||
| id: `http://schema.org/${fieldName}`, |
There was a problem hiding this comment.
By definition, we cannot guess the Schema.org mapping from a Swagger file (JSON-LD must be used for this). The id should always be null when using Swagger.
It's maybe possible to add such mappings with OpenAPI v3, I've not checked.
| fieldName => | ||
| new Field(fieldName, { | ||
| id: `http://schema.org/${fieldName}`, | ||
| range: null, |
There was a problem hiding this comment.
It should be possible to map Swagger types to a RDF ranges. Can be done in a second step anyway.
| new Field(fieldName, { | ||
| id: `http://schema.org/${fieldName}`, | ||
| range: null, | ||
| reference: null, |
There was a problem hiding this comment.
It should be possible to guess if this field is a relation or not using Swagger. Can be done in a second step anyway.
| ); | ||
|
|
||
| return new Resource(name, url, { | ||
| id: `http://schema.org/` + title, |
There was a problem hiding this comment.
Same here, it cannot start with http://schema.org/ (should be null IMO)
|
Have you tried to use your branch with admin or client-generator to see if it works well? |
|
Hi @dunglas, thank you for your time reviewing my PR. I just made some adjusts as you asked. About the client-generator... Yes, I tried. My PR there is already tested. |
|
Thanks @arojunior |
* add support to parse Swagger format * eslint fixes * adjusts required by revision to swagger parser
The work still in progress, but I'm open this Pull Request just to let you guys know how it is going.
I'm open a PR to client-generator as well, including this feature.