Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apisprout is rejecting perfecly valid json references #40

Open
larsks opened this issue May 31, 2019 · 5 comments
Open

apisprout is rejecting perfecly valid json references #40

larsks opened this issue May 31, 2019 · 5 comments
Labels
bug Something isn't working upstream

Comments

@larsks
Copy link

larsks commented May 31, 2019

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.

@danielgtaylor danielgtaylor added bug Something isn't working upstream labels Jun 7, 2019
@geminiyellow
Copy link

geminiyellow commented Sep 11, 2019

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.

@btkelly
Copy link

btkelly commented Dec 5, 2019

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

@gki
Copy link

gki commented Sep 23, 2020

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

@nym3r0s
Copy link

nym3r0s commented Jul 26, 2021

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
Copy link

nym3r0s commented Jul 29, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream
Projects
None yet
Development

No branches or pull requests

6 participants