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

fix(repository-json-schema): update to pass openapi validation in azure #3504

Merged
merged 1 commit into from
Sep 27, 2019

Conversation

ericzon
Copy link

@ericzon ericzon commented Aug 4, 2019

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

This PR is related with my comment in #1466 about problems found during the process of deploy an API in Azure.
With this PR is possible to deploy an API as "App Service" and connect it with the API Manager as OpenAPI.
I added the optional key 'itExtendsCompatibility' (boolean) in JsonSchemaOptions to tackle these cases. By default uses the current behaviour.
Added some tests, applied prettier & linter of the project.

P.S: by the way, trying to sign your CLA gives a 504 Error in Cloudfront.

@raymondfeng
Copy link
Contributor

@ericzon Thank you for the patch. I had a similar concern in the past - see #3309 (comment).

@dhmlau
Copy link
Member

dhmlau commented Aug 6, 2019

FYI - the failure on Travis is a timeout error:

1) cloneExampleFromGitHub (SLOW)
       extracts project files:
     Error: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/travis/build/strongloop/loopback-next/packages/cli/test/integration/generators/clone-example.integration.js)
      at listOnTimeout (internal/timers.js:531:17)
      at processTimers (internal/timers.js:475:7)

@dhmlau
Copy link
Member

dhmlau commented Aug 6, 2019

@slnode test please

@raymondfeng
Copy link
Contributor

@nabdelgadir Please review the PR.

Copy link
Contributor

@nabdelgadir nabdelgadir left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, just a couple comments.

@dhmlau
Copy link
Member

dhmlau commented Aug 13, 2019

@nabdelgadir, is this good to land?

@nabdelgadir
Copy link
Contributor

@dhmlau not yet.

@ericzon, what do you think about @raymondfeng's proposal?

  1. Make schema title compatible by default with a bit less expressivity (IIRC, the title needs to be unique)
  2. Populate schema description to make it readable

@dhmlau
Copy link
Member

dhmlau commented Aug 14, 2019

Thanks @nabdelgadir . Let me assign it to you since you're already helping this PR.

@ericzon
Copy link
Author

ericzon commented Aug 15, 2019

@dhmlau not yet.

@ericzon, what do you think about @raymondfeng's proposal?

  1. Make schema title compatible by default with a bit less expressivity (IIRC, the title needs to be unique)
  2. Populate schema description to make it readable

@nabdelgadir for me it's ok, compatible by default. @raymondfeng in 2 you propose to add some kind of extra & dynamic description like:

"description": "[original description]... Product excluding fields id, name"

right?

bajtos
bajtos previously requested changes Aug 16, 2019
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

Thank you @ericzon for the pull request! I agree we should emit schema titles that are compatible with a wide range of OpenAPI/JSON Schema consumers 👍

I disagree with the proposed implementation, let's find a better one.

packages/repository-json-schema/src/build-schema.ts Outdated Show resolved Hide resolved
@raymondfeng
Copy link
Contributor

@ericzon Would you please make the final update based on the team agreement? Thanks!

@ericzon
Copy link
Author

ericzon commented Aug 21, 2019 via email

@ericzon
Copy link
Author

ericzon commented Aug 24, 2019

Updated. Now is compatible by default & description includes information about model options.

Example of model names & descriptions:

"TechnicalData"
"Description about TechnicalData model"

"TechnicalDataExcluding_id-createdAt_"
"Description about TechnicalData model (Model options: Excluding[id,createdAt])"

"TechnicalDataPartial"
"Description about TechnicalData model (Model options: Partial)"

"TechnicalDataWithRelations"
"Description about TechnicalData model (Model options: WithRelations)"

I tested in Azure to import the generated definition and is accepted.
...

@bajtos bajtos dismissed their stale review September 2, 2019 14:21

The major issues have been addressed.

@bajtos bajtos self-assigned this Sep 10, 2019
@bajtos
Copy link
Member

bajtos commented Sep 10, 2019

@ericzon I would love to see this pull request landed soon, let me know how can I help.

@raymondfeng raymondfeng force-pushed the fix/adapt-to-azure-openapi branch from 2505074 to c0fd6c2 Compare September 12, 2019 20:34
@raymondfeng
Copy link
Contributor

@ericzon I have rebased your branch against latest master and squashed all commits into one.

@bajtos
Copy link
Member

bajtos commented Sep 13, 2019

I would like the code building title suffix to be kept simple with hardcoded start/delimiter/end characters and also improve the code building options description to use JSON.stringify or stringify-object.

I feel the current proposal is adding too much complexity that will make the code more difficult to maintain for us.

@ericzon
Copy link
Author

ericzon commented Sep 15, 2019

@bajtos pushed a simplified version using stringify-object.
I couldn't reuse stringifyModelSettings from utils because it creates a wrapper with settings field and we want the stringified version in a single line.

@raymondfeng raymondfeng force-pushed the fix/adapt-to-azure-openapi branch from 1f8b31e to 7535e69 Compare September 16, 2019 19:40
@raymondfeng
Copy link
Contributor

@ericzon I have rebased your branch against latest master of strongloop/loopback-next. In the future, please use the following to pull in latest changes from upstream:

git remote add upstream [email protected]:strongloop/loopback-next.git
git fetch --all
git rebase upstream/master

@bajtos
Copy link
Member

bajtos commented Sep 20, 2019

pushed a simplified version using stringify-object.
I couldn't reuse stringifyModelSettings from utils because it creates a wrapper with settings field and we want the stringified version in a single line.

@ericzon I don't see this change being applied to the patch. I don't see any new commits pushed around the time you have posted the comment. Did you perhaps forgot to git push the change?

@ericzon ericzon force-pushed the fix/adapt-to-azure-openapi branch 5 times, most recently from 86a1ef9 to fe2119f Compare September 23, 2019 10:49
@ericzon
Copy link
Author

ericzon commented Sep 23, 2019

@bajtos now the changes are ready to check. I've squashed and rebase too.

Copy link
Contributor

@raymondfeng raymondfeng left a comment

Choose a reason for hiding this comment

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

Please address my comments.

@ericzon ericzon force-pushed the fix/adapt-to-azure-openapi branch 2 times, most recently from 56f9d60 to 595fc54 Compare September 24, 2019 10:57
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

LGTM with two nit-picks that can be ignored.

@raymondfeng WDYT?

@ericzon ericzon force-pushed the fix/adapt-to-azure-openapi branch 2 times, most recently from 8d4af5c to a3d8c00 Compare September 24, 2019 18:06
@ericzon ericzon force-pushed the fix/adapt-to-azure-openapi branch from a3d8c00 to f4799ea Compare September 24, 2019 20:39
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

Almost there!

"@hapi/hoek": "8.x.x"
}
},
"@loopback/build": {
Copy link
Member

Choose a reason for hiding this comment

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

Please revert changes in package-lock.json file. Now that you are not adding new dependencies, there is no need to change the lock file either.

For future reference: https://github.com/strongloop/loopback-next/blob/master/docs/site/DEVELOPING.md#working-with-dependencies
Here is the important part: Dependencies resolved locally within the monorepo must be excluded from package-lock files.

Copy link
Member

Choose a reason for hiding this comment

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

Nice, this problem was catched by our linter, I forget we have one in place!

See https://travis-ci.com/strongloop/loopback-next/jobs/238791798

Invalid package-lock entries found!
  packages/repository-json-schema/package-lock.json
    -> @loopback/build
    -> @loopback/context
    -> @loopback/core
    -> @loopback/eslint-config
    -> @loopback/metadata
    -> @loopback/repository
    -> @loopback/testlab

Run the following command to fix the problems:

  $ npm run update-package-locks

Please don't run update-package-locks and just revert changes in this file. We prefer to update lock files via https://renovatebot.com

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I followed the suggestion of travis. Reverted.

@@ -15,6 +15,7 @@ import {
import * as debugFactory from 'debug';
import {JSONSchema6 as JSONSchema} from 'json-schema';
import {JSON_SCHEMA_KEY, MODEL_TYPE_KEYS} from './keys';
const nativeUtils = require('util');
Copy link
Member

Choose a reason for hiding this comment

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

Please use ES6 imports.

Suggested change
const nativeUtils = require('util');
import {inspect} from 'util';

Or if you want to import everything:

Suggested change
const nativeUtils = require('util');
import * as nativeUtils from 'util';

Copy link
Author

Choose a reason for hiding this comment

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

Changes updated

@ericzon ericzon force-pushed the fix/adapt-to-azure-openapi branch from f4799ea to c353a63 Compare September 26, 2019 14:30
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

👏

Let's get approval from @raymondfeng too.

Copy link
Contributor

@nabdelgadir nabdelgadir left a comment

Choose a reason for hiding this comment

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

👏

@raymondfeng raymondfeng merged commit b518876 into loopbackio:master Sep 27, 2019
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.

6 participants