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.

Two schemas are referenced with the same name but different content. Renamed Item to Item-2.

See original GitHub issue

If using subdirectories to organize a large number of components and some of these components share the same file basename (but exist in different subdirectories) you get warnings like this:

[6] paths/beta/rating/merchantRates.yaml:59:7 at #/get/parameters/3

Two schemas are referenced with the same name but different content. Renamed fields to fields-5.

This also comes up with models like models/Order/Item.yaml and models/Shipment/Item.yaml because both files are named Item so they are merged in as Item and Item-2 and so-on.

Example spec

openapi.yaml

openapi: 3.0.3
info:
  title: test
paths:
  '/api/global/beta/rating/rateGroups':
    $ref: 'paths/beta/rating/rateGroups.yaml'
  '/api/global/beta/rating/merchantRates':
    $ref: 'paths/beta/rating/merchantRates.yaml'

paths/beta/rating/rateGroups.yaml

get:
  summary: List all Rate Groups
  description: foo
  parameters:
    - $ref: ../../../components/parameters/rate/group/fields.yaml

paths/beta/rating/merchantRates.yaml

get:
  summary: List all Merchant Rates
  description: foo
  parameters:
    - $ref: ../../../components/parameters/merchant/rate/fields.yaml

Expected behavior The refs are valid so ideally there should not be such warnings and ideally it should not require the refs to be declared explicitly in the top level file as a workaround as that is much more tedious than just directly referencing the files where they are needed.

openapi-cli Version(s) 1.0.0-beta.73

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
colinmollenhourcommented, May 3, 2022

I like them remaining as references as that keeps the spec concise and agree that the warnings can safely be ignored but then other warnings get masked quickly… Using one parent folder name as a prefix would be a big improvement in my opinion and probably work in 95% of cases. As of now I’ve resorted to naming files like Order/OrderItem.yaml instead of Order/Item.yaml to avoid the warnings.

1reaction
pvonrcommented, Jun 10, 2022

We would like to have the revers behavior 😃 Instead of deduplicating models via adding a number automatically I’d like to error out if this is happening. Is there a way to achieve this?

Context: We have our specs distributed in different repos and bundle it into one big public spec. It’s semantically incorrect for us to have different models with the same name. If this happens the names are too generic and should be revised (e.g. in the above example it should be OrderItem and ShippingItem). Having this we could enforces clear domain based naming schemes and fail fast if people introduce naming conflicts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Schema reference having a same name as the ... - GitHub
Here there are two schema having the same name. Can this be referenced like wise. Open API cannot have duplicate schema under components....
Read more >
MSBuild Items - Microsoft Learn
MSBuild items are inputs into the build system, and they typically represent files (the files are specified in the Include attribute). Items are ......
Read more >
Adding Examples - Swagger
Note that schemas and properties support single example but not multiple examples . Array Example. You can add an example of an individual...
Read more >
XML Schema Part 2: Datatypes Second Edition - W3C
Two strings or names being compared must be identical. Characters with multiple possible representations in ISO/IEC 10646 (e.g. characters with ...
Read more >
how to use same component schemas using $ref which vary a ...
Check the JSON Schema docs on combining schemas; in this particular case you'd use allOf , for example. Here's a related answer.
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