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

How to start with initialized data?

Open klaygomes opened this issue 10 years ago • 1 comments

Is it possible to start swagger server with initialized mock data? I tried using examples property from responses in swagger but it didnt work.

 /empresas:
    get:
      description: some description
      parameters:
        - $ref: "#/parameters/empresa"
      responses:
        '200':
          schema:
            title: ArrayOfEmpresa
            type: array
            items:
              $ref: "#/definitions/empresa"
          examples:
            application/json:
              - nome: Teste 1
                id: 1
              - nome: Teste 2
                id: 2

klaygomes avatar Dec 21 '15 20:12 klaygomes

I'm not sure you can add mock data to the yaml file.

However, I've been testing this project today and noticed that on sample 3 he demonstrates a way to initialize mock data. The data is loaded from @bigstickcarpet/mock-data - which is a directory within node_modules. See line 5 of employess.js

When loadMockData is executed during initialization it saves the employees in the mock data store.

You can follow a similar pattern to add initial data.

fcardona avatar Dec 22 '15 04:12 fcardona