question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using external file with all definitions doesn't work

See original GitHub issue

We have a file with all the definitions for a given service in a separated file and we need to reuse it in multiple api definitions but we cannnot import it. The definition original definition file use model with nested models etc and we need to import a lot of these, we cannot repeat all the names with all the $refs in every api definition.

In this example we need import all the definitions from _testdrivemulti.yaml and use it in the main api definition but it doesn’t work.

# Testing swagger
swagger: '2.0'
info:
  title: API ejemplo QIS
  description: Un ejemplo de definición para QIS usando swagger
  version: "1.0.0"
host: www.example.com
# array of all schemes that your API supports
schemes:
  - https
# will be prefixed to all paths
basePath: /v1
produces:
  - text/xml
  - application/json
securityDefinitions:
  apiKey:
    type: apiKey
    name: api_key
    in: query
paths:
  /testdrives:
    get:
      summary: Test Drives
      description: Detalle de vehículos
      security:
        - api_key: []
      parameters:
        - name: filtros
          in: body
          description: Body con todos los filtros aplicables
          required: true
          schema:
            $ref: '#/definitions/BusquedaGenerica'
      responses:
        200:
          description: Todo correcto
          schema:
            $ref: '#/definitions/TestDrive'

        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'
definitions:
  $ref: './_testdrivemulti.yaml'
  Error:
    properties:
      code:
        type: integer
        format: int32
      message:
        type: string
      fields:
        type: string

Cliente:
  x-dms-file: FMCUCG
  properties:
    nombre:
      type: string
    apellido1:
      type: string
TestDrive:
  x-dms-file: FXTESTDRIVEPT
  properties:
    idv:
      type: integer
      description: Id del vehículo
    cliente:
      type: object
      $ref: '#/definitions/Cliente'

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
webroncommented, Sep 19, 2016

@diegode That’s a common mistake, but Swagger syntax is not a subset of JSON Schema. The Schema Object, under the Swagger spec is a subset of JSON Schema. The rest of the structure is just a JSON format we chose, and we chose to support JSON References in some places. I won’t go into it here, but there are pros and cons to allowing JSON References everywhere. I agree we should extend the locations, I disagree we should allow them everywhere.

In any case, just because other tools dereference all the references automatically, doesn’t make them right 😉

0reactions
fehguycommented, Oct 21, 2016

OK got it. There are two modes for the parser, which includes “resolving” and simply parsing. If resolving, it will pull remote definitions into the local file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Function in an external file doesn't work - Stack Overflow
A script tag can't have a src attribute and a body at the same time. The body will be ignored and the script...
Read more >
External links may be calculated when you open a workbook
When you open the linked workbook and confirm that all external links have updated successfully and that the workbook has been successfully ...
Read more >
jsconfig.json Reference - Visual Studio Code
json: A JavaScript project is defined via a jsconfig.json file. The presence of such a file in a directory indicates that the directory...
Read more >
Referencing External Files - SAS OnlineDoc, V8
Depending on the context, SAS can reference an external file by using: ... The following example reads all files in the current working...
Read more >
Modules, introduction - The Modern JavaScript Tutorial
If you try to open a web-page locally, via file:// protocol, you'll find that import/export directives don't work. Use a local web-server, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found