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

Handle structure difference #8231

Merged

Conversation

ishuen
Copy link
Contributor

@ishuen ishuen commented Oct 14, 2022

Description

See #8218

Motivation and Context

The current json parsing logic is not able to handle OAS3's structure well.

How Has This Been Tested?

Manual test plus unit test

Screenshots (if appropriate):

Screenshot1 https://ibb.co/DLLqygT
Screenshot2 https://ibb.co/HKvSfzL

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

@tim-lai
Copy link
Contributor

tim-lai commented Oct 19, 2022

@ishuen Thanks for the issue and PR. I made a comment in issue #8218 for additional information. That said, I also did a quick test in SwaggerUI of the provided definition (both json and yaml formats), and I don't reach the non- parameter.get("schema") case, as referenced in the proposed change:

if (!parameter.get("schema")) {
    console.log("DEBUG: no schema case. parameter:", parameter.toJS())
  }
schema: parameter.get("schema") ? parameter.get("schema", Im.Map()): parameter,

@ishuen
Copy link
Contributor Author

ishuen commented Oct 20, 2022

Hi @tim-lai . Could you provide your test json file?
I tried it with this json file modified from the sample Petstore definition, which is generated from swagger editor . Please check GET /pet/{hasPetId} for boolean case and GET pet/findByTags for enum case.

@tim-lai
Copy link
Contributor

tim-lai commented Oct 20, 2022

Could you provide your test json file?

from the linked issue: https://github.com/cywhale/test_swagger/blob/main/public/test.json

Please check GET /pet/{hasPetId} for boolean case and GET pet/findByTags for enum case.

Ok, I see the "progression" to the non-schema case now.

Imo, adding the fallback to parameter is incorrect, as a parameter object is different from a schema object. So if no schema is provided, we should return an empty value (Map). Are you on the same environment as the original poster in #8218 ? If so, can you try fallback to Im.Map() instead and see if the devTools errors disappear?

Basically, I think the definition provider should provide a schema, style, or content per the Parameter Object documentation, that matches the boolean or enum case. So this PR should be limited to improving error handling.

@ishuen
Copy link
Contributor Author

ishuen commented Oct 22, 2022

Hi. Thanks for the suggestion, the fallback is replaced by an empty map.

@ishuen ishuen force-pushed the bug/8218-fix-boolean-and-enum-rendering branch from b34fde7 to d953ec4 Compare October 24, 2022 09:42
@ishuen
Copy link
Contributor Author

ishuen commented Oct 24, 2022

Fixed the dev env issue.
Root cause: the expected data type of allowedValues defined in Select is array. (See layout-utils.jsx)

@ishuen ishuen force-pushed the bug/8218-fix-boolean-and-enum-rendering branch from d953ec4 to 39c7a73 Compare October 24, 2022 09:53
@@ -85,7 +85,7 @@ export class JsonSchema_string extends Component {
const Select = getComponent("Select")
return (<Select className={ errors.length ? "invalid" : ""}
title={ errors.length ? errors : ""}
allowedValues={ enumValue }
allowedValues={ Array(...enumValue) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer spread array shorthand

Suggested change
allowedValues={ Array(...enumValue) }
allowedValues={ [...enumValue] }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks.

const Select = getComponent("Select")

return (<Select className={ errors.length ? "invalid" : ""}
title={ errors.length ? errors : ""}
value={ String(value) }
disabled={ disabled }
allowedValues={ enumValue || booleanValue }
allowedValues={ enumValue ? Array(...enumValue) : booleanValue }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer spread array shorthand

Suggested change
allowedValues={ enumValue ? Array(...enumValue) : booleanValue }
allowedValues={ enumValue ? [...enumValue] : booleanValue }

@tim-lai
Copy link
Contributor

tim-lai commented Oct 24, 2022

Root cause: the expected data type of allowedValues defined in Select is array. (See layout-utils.jsx)

Nice! I added a small suggestion to update, otherwise almost there!

@ishuen
Copy link
Contributor Author

ishuen commented Oct 25, 2022

Thanks, the change is applied.

@tim-lai tim-lai merged commit 2a967e9 into swagger-api:master Oct 25, 2022
@tim-lai
Copy link
Contributor

tim-lai commented Oct 25, 2022

@ishuen PR merged! Thanks for the investigation and fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants