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

Wrong model titles when composing using allOf

Open lekoder opened this issue 9 years ago • 21 comments

When composing models using allOf, swagger-ui displays wrong model title for composed model. It uses last model referenced in allOf instead of one defined.

Definition:

definitions:
  Simple1:
    type: object
    properties:
      id1:
        type: integer
        format: int64
  Simple2:
    type: object
    properties:
      id2:
        type: integer
        format: int64
  Composed:
    allOf:
      - $ref: '#/definitions/Simple1'
      - $ref: '#/definitions/Simple2'

Expected result:

Simple1{...}
Simple2{...}
Composed{...}

Actual result:

Simple1{...}
Simple2{...}
Simple2{...}

Affected version: v3.0.0-229-g7790383

Ghist with full issue demonstration

lekoder avatar Apr 21 '17 05:04 lekoder

Same issue is affecting latest master: v3.0.0-235-g6cd66bb

lekoder avatar Apr 21 '17 05:04 lekoder

It seems that underlying problem is that schema of model composed with allOf has $$ref key of last items in allOf array.

lekoder avatar Apr 21 '17 07:04 lekoder

This seems like swagger-js issue.

lekoder avatar Apr 21 '17 08:04 lekoder

Just added a test on SwaggerJS, it passes: https://github.com/buunguyen/swagger-js/commit/5421ff87f6d26fe593781a04e2677232daefdf1f. Seems to work fine on JS side.

buunguyen avatar May 17 '17 18:05 buunguyen

Using the fix in @lekoder 's commit, I was able to resolve an issue I was facing. Thanks.

The distribution files I am using are in my fork.

However, the name of the model in the 200 response section is still wrong and pointing to the subclass.

wjlow avatar Jun 02 '17 00:06 wjlow

I have encountered the same problem, how is the progress?

Xuanwo avatar Jun 15 '17 11:06 Xuanwo

We're not working on a fix right now. Would be happy to review PRs.

webron avatar Jun 15 '17 15:06 webron

This appears to be fixed:

image

Closing - please ping if there are any further problems with this!

shockey avatar Aug 01 '17 06:08 shockey

@shockey This problem is still occurring for me in Swagger UI. I just pulled the latest 3.1.2 and it is still showing the base model name and description as I described in #3417 using https://github.com/swagger-api/swagger-ui/files/1160284/duplicate-models.yaml.txt I verified that my browser is not showing cached swagger-ui content.

DavidBiesack avatar Aug 01 '17 20:08 DavidBiesack

@DavidBiesack, your problem is valid but slightly different. This issue centers around inheriting the name based on the key name of the model, and yours has to do with the title property.

We'd be happy to look into it - can you open a new issue since this one is fixed?

shockey avatar Aug 02 '17 18:08 shockey

@shockey Please reopen #3417 which covers it all already - it was closed as a dup of this but apparently it is not really a dup. Thanks!

DavidBiesack avatar Aug 02 '17 19:08 DavidBiesack

@DavidBiesack sure, reopening now.

shockey avatar Aug 02 '17 19:08 shockey

This is still happening to me both in the web version and in the docker image (swaggerapi/swagger-editor:latest). Does it still have to be merged somehow?

image

marcoreni avatar Aug 10 '17 09:08 marcoreni

Confirmed.

webron avatar Aug 10 '17 13:08 webron

this caused the regression... https://github.com/swagger-api/swagger-ui/pull/3514 . So we need to ensure we don't regress on https://github.com/swagger-api/swagger-ui/issues/3505 as we fix this regression :grin:

ponelat avatar Aug 25 '17 13:08 ponelat

Also seeing this is my internal fork (updated to b6cd504 currently). I'm looking to resolve the issue this week hopefully - will try to submit a PR here as well.

Update: My team (not associated with SmartBear / Swagger team) decided not to pursue this issue currently. I did some preliminary research, and the issue seems to be very much what @lekoder suggests. In swagger-js, a model composed using allOf will pull all props, including references. This means that as the tree is resolved, references get walked all the way back up to the root reference.

In our case, we are working with an OData based API, and all of our entities inherit from a base OData.Entity type. This bug causes our entire model to display only OData.Entity for types, as all the $refs were resolved up the tree.

We ended up reverting #3514 on our internal build for now.

dballance avatar Aug 28 '17 16:08 dballance

What about? I'm trying editor.swagger.io, but still the same problem.

schermafbeelding 2017-08-29 om 16 25 33

schellingerht avatar Aug 29 '17 14:08 schellingerht

Hi,

Me too... any estimation when is it going to be solved?

tvappagency avatar Sep 04 '17 13:09 tvappagency

A small fix: change properties to - properties, so only the model name is wrong. The content is good.

2017-09-04 15:22 GMT+02:00 tvappagency [email protected]:

Hi,

Me too... any estimation when is it going to be solved?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/swagger-api/swagger-ui/issues/2946#issuecomment-326962312, or mute the thread https://github.com/notifications/unsubscribe-auth/AK3QZgehEsMT54nxt9H24ZgfsGawe24xks5se_mZgaJpZM4ND4MA .

schellingerht avatar Sep 04 '17 13:09 schellingerht

Fixed by https://github.com/swagger-api/swagger-js/pull/1130, which should be released this week 🎉

messages image 3264158295

shockey avatar Sep 12 '17 01:09 shockey