apisprout icon indicating copy to clipboard operation
apisprout copied to clipboard

apisprout is rejecting perfecly valid json references

Open larsks opened this issue 5 years ago • 5 comments

I have in my main spec document something like this:

components:
  ListOfWidgets:
    $ref: 'parts/widget/model.yaml#/ListOfWidgets`
  Widget:
    $ref: 'parts/widget/model.yaml#/Widget`

And parts/widget/model.yaml looks something like this:

ListOfWidgets:
  type: array
  items:
    $ref: '#/Widget'

Widget:
  properties:
    id:
      type: string
    description:
      type: string

apisprout rejects this because:

2019/05/31 14:37:49 expected prefix '#/components/schemas/' in URI '#/ListOfWidgets'

That seems unreasonable. apisprout should not be enforcing restrictions on the organization of documents. These are not schemas because the path includes #/components/schemas; they are schemas because they are included by reference in the schemas section of the specification.

larsks avatar May 31 '19 14:05 larsks

ok, i have the same problem,

in the openapi.yaml

paths:
  /count:
    get:
      operationId: getCount
      description: get count
      tags:
        - count
      responses:
        '200':
          description: success response
          content:
            application/json:
              schema:
                $ref: 'models/Count.yaml'

and in the Count.yaml

title: Count
type: object
properties:
  data:
    type: object
    properties:
      count:
        type: number
        default: 1
        minimum: 0

then

apisprout openapi.yaml
2019/09/11 10:41:03 expected prefix '#/components/schemas/' in URI '#'

i dont have any key like #/components/schemas/, why?

and i check the OpenAPI Specification in here and here, i dont think my yaml is invalid.

geminiyellow avatar Sep 11 '19 01:09 geminiyellow

I'm having the same issue. I prefer to break up my spec files to make them easier to maintain but APISprout doesn't seem to like refs in the file format like `$ref: ./models/myObject.yaml' but that is perfectly valid as defined here https://swagger.io/docs/specification/using-ref/#syntax

btkelly avatar Dec 05 '19 19:12 btkelly

facing same issue. is there any update to fix this issue??

gki avatar Sep 23 '20 02:09 gki

Facing the same issue here. Looking to adopt this for a $ref based schema and it is not working. My API is too large to write into a single schema file.

nym3r0s avatar Jul 26 '21 15:07 nym3r0s

If anyone else is facing this, here's a workaround that I have for now which uses swagger-cli to generate a single file after resolving all the references. However, this creates additional dependencies on node/npm but lets you keep your project structure as is.

# Install swagger-cli using npm
npm install -g swagger-cli
# Bundle the modular OpenAPI spec into a single, condensed spec file.
swagger-cli bundle ./src/openapi.yaml --outfile ./build/openapi.yaml --type yaml
# Use ApiSprout to run the condensed file.
apisprout ./build/openapi.yaml

Using Docker:

FROM node:12.18.1 as build
WORKDIR /
COPY src/ /
RUN npm install -g swagger-cli && \
    swagger-cli bundle /openapi.yaml --outfile /_build/openapi.yaml --type yaml

FROM danielgtaylor/apisprout
COPY --from=build /_build/openapi.yaml /openapi.yaml

nym3r0s avatar Jul 29 '21 12:07 nym3r0s