swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

Parse a modularized Swagger specification

Open RobWin opened this issue 10 years ago • 9 comments

Hello,

should it be possible to parse a modularized a Swagger specification? The parsed Swagger Java Model does not contain the content of the referenced files. Does the swagger-parser support JSON references for all attributes? Or, can I only use JSON references for attributes which are parsed into a RefModel?

Example:

swagger: '2.0'
info:
  $ref: "./info.yaml"
host: petstore.swagger.io
basePath: /v2
schemes:
  - http
tags:
  - name: pet
    description: Pet resource
  - name: store
    description: Store resource
  - name: user
    description: User resource
paths:
  $ref: "./paths.yaml"
parameters:
  $ref: "./parameters.yaml"
responses:
  $ref: "./responses.yaml"
definitions:
  $ref: "./definitions.yaml"
securityDefinitions:
  $ref: "./security_definitions.yaml"

RobWin avatar Nov 16 '16 12:11 RobWin

Hi, only if the spec supports it. What you have here is not legal based on https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md

fehguy avatar Nov 16 '16 14:11 fehguy

ok. Thx

RobWin avatar Nov 16 '16 15:11 RobWin

Means the following example (in the blog post) does not work, because swagger-parser does not support JSON references similar to https://github.com/whitlockjc/json-refs.

Blog post: http://azimi.me/2015/07/16/split-swagger-into-smaller-files.html

Would it make sense to integrate https://github.com/adjohnson916/jackson-json-reference into the swagger-parser?

RobWin avatar Nov 16 '16 15:11 RobWin

json-refs is a standard mechanism, the spec supports them in only specific locations.

The blog post you mentioned is flat out wrong, and should not be referenced.

Recall this is not necessarily a technical limitation--of course references could be supported anywhere one wants but the specification--for good reason--does not support them being used arbitrarily.

fehguy avatar Nov 16 '16 15:11 fehguy

Thanks. What are the good reasons? :)

RobWin avatar Nov 16 '16 15:11 RobWin

This would be a good time to jump over to that repo and read the issues & comments, that's the place for these types of discussions

fehguy avatar Nov 16 '16 15:11 fehguy

ok. Thank you anyway.

RobWin avatar Nov 16 '16 15:11 RobWin

does it can generate sub package for deferent models? My file struct: index.yaml path/SeviceA/pathA.yaml path/SeviceB/pathB.yaml definitions/SeviceA/domain/A.yaml definitions/SeviceB/domain/A.yaml How to generate class folders like this: servicea servicea.domain serviceb seviceb.domain

zcb22000 avatar Jan 22 '17 01:01 zcb22000

@zcb22000 Please look at what is supported in the spec.

fehguy avatar Jan 22 '17 04:01 fehguy