[Generic] Generating client code from a big YAML file
@wing328 It would be nice if swagger spec can provide an option to include another spec. Just line “# include” in C/C++. The reason to request for this feature is, yaml getting quite big, and prone to errors. In fact, becomes quite difficult to follow at times. We understand that, yaml as such does not provide any include feature, and to keep it yaml compliant, only way to achieve this would be via some property or type. Please let us know if you think there is already a way to resolve this or this is a valid issue to provide as a feature. I am sure there would be challenges in case of sending yaml over wire, where includes could become an issue … but there are ways to solve this.
You may want to share the spec here so that the community can look into the issue. (I'm out this week and may not have access to the Internet)
I assume the spec has been validated using editor.swagger.io or other tools.
@wing328 Please find below scenario. We have YAML file having details of around 10 service details. Request and responses has many parameters. So the length of file getting increased around 1000+ lines. Then in this case its very difficult to maintain the single YAML. It would be great if there are any way for swagger to read the Parent YAML file and resolve all child YAML mentioned in parent YAML. So that user will break it into different Yaml and mention the references of these different YAML file in single parent YAML.
Are you referring to relative schema? Ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#relative-schema-file-example
@wing328 I have tried this, but didnt get success. Please find below my Pet Parent file along with the Pet definition file which I put as reference. After executing these from command line I am not getting any exception client code getting generated without Pet model. Please correct me if I am doing anything wrong
I have PetFull.yaml, in that I have mentioned refrence for another yaml as $ref: 'Pet.yaml'
PetFull.yaml
`swagger: '2.0' info: version: '1.0.0' title: Swagger Petstore (Simple) description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification termsOfService: http://helloreverb.com/terms/ contact: name: Swagger API team email: [email protected] url: http://swagger.io license: name: MIT url: http://opensource.org/licenses/MIT host: petstore.swagger.io basePath: /api schemes:
- http consumes:
- application/json produces:
- application/json paths: /pets: get: description: Returns all pets from the system that the user has access to operationId: findPets produces: - application/json - application/xml - text/xml - text/html parameters: - name: tags in: query description: tags to filter by required: false type: array items: type: string collectionFormat: csv - name: limit in: query description: maximum number of results to return required: false type: integer format: int32 responses: '200': description: pet response schema: type: array items: $ref: 'Pet.yaml' `
Pet.yaml
`pet: type: object required:
- id
- name properties: id: type: integer format: int64 name: type: string tag: type: string`
Sorry, I am not able to attach the files. I have pasted file from clipboard as code snippet.
@wing328 .... I took swagger parser project and compared whatever I did. I found issue and resolved that. Thanks for your help. :+1:
@wing328 .. I followed Pet example from swagger parser project and resolved that $ref issue. But during client generation I am getting below warnings for models. Could you please let me know, is there any specific reason for this warning?
[main] WARN io.swagger.util.PropertyDeserializer - no property from null, null, {ENUM=null, TITLE=null, DESCRIPTION=null, DEFAULT=null, PATTERN=null, DESCRIMINATOR=null, MIN_ITEMS=null, MAX_ITEMS=null, MIN_PROPERTIES=null, MAX_PROPERTIES=null, MIN_LENGTH=null, MAX_LENGTH=null, MINIMUM=null, MAXIMUM=null, EXCLUSIVE_MINIMUM=null, EXCLUSIVE_MAXIMUM=null, UNIQUE_ITEMS=null, EXAMPLE=null, TYPE=null, FORMAT=null, READ_ONLY=null, VENDOR_EXTENSIONS={}}
@wing328 really sorry to bother you again... above warning message got resolved. Closing issue
@sbelan no worry :)