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

Support for Joi 14 | Example #540

Closed
montumodi opened this issue Nov 13, 2018 · 11 comments
Closed

Support for Joi 14 | Example #540

montumodi opened this issue Nov 13, 2018 · 11 comments
Milestone

Comments

@montumodi
Copy link

Context

  • hapi-swagger version: 9.1.2
  • hapi: 17
  • Joi: 14

What are you trying to achieve or the steps to reproduce?

We have recently upgraded our hapi from version 16 to 17, Joi from 12 to 14 and hapi swagger from 7 to 9. Since than our examples on the documentation page are coming incorrect.

Previous

{
  "someField": "someValue"
}

Now

{
  "someField": {"value": "someValue"}
}

Json schema looks like this

{"someField": Joi.string().example("someValue")}

because of this if someone clicks on example and click "Try It out" it gives bad request because schema doesn't allow "value".

I guess this is related to Joi 14 in which examples have started to come in value. Is there any workaround, options or plan to fix this?

@robmcguinness
Copy link
Collaborator

robmcguinness commented Nov 13, 2018

looks like Joi v14 was released 22 days ago. Current version supported is v13. Pinning the release notes for v14 for future reference: hapijs/joi#1615

@nickeljew
Copy link

Please fixed code in lib/properties.js line 221 as following:

property.example = Hoek.reach(joiObj, '_examples.0.value');

@laurilarjo
Copy link

^ The above worked for me also.

@robmcguinness
Copy link
Collaborator

Created a branch: https://github.com/glennjones/hapi-swagger/tree/feature/upgrade-joi with above fix but there are 3 failing tests.

https://travis-ci.org/glennjones/hapi-swagger/jobs/485966120

I don't have time to look at this further but maybe others can help out.

@laurilarjo
Copy link

Thanks. Just noticed that someone had tried this as a pull request earlier with a faulty title: #546

@robmcguinness
Copy link
Collaborator

@laurilarjo ah good catch. I never got feedback for the changes requested in #546.

@robmcguinness robmcguinness added this to the v10 milestone Feb 2, 2019
lucasconstantino added a commit to lucasconstantino/joi-to-swagger that referenced this issue Feb 6, 2019
lucasconstantino added a commit to lucasconstantino/joi-to-swagger that referenced this issue Feb 6, 2019
@robmcguinness
Copy link
Collaborator

Notes about Joi v14 upgrade:

  • there was a breaking change to correctly apply labels to alternatives schemas 14.0.0 Release Notes hapijs/joi#1615: Error messages could look weird when you chain a label with an alternative, say Joi.when('foo', { ... }).label('myLabel'). Now it is correctly dealt with.
  • consequently, one of the unit test for alternatives is breaking.

Expecting:

{
  "in": "body",
  "name": "body",
  "schema": {
    "$ref": "#/definitions/Alt"
  },
  "x-alternatives": [
    {
      "$ref": "#/x-alt-definitions/alt1" // <==
    },
    {
      "$ref": "#/x-alt-definitions/alt2" // <==
    }
  ]
}

Actual:

{
  "in": "body",
  "name": "body",
  "schema": {
    "$ref": "#/definitions/Alt"
  },
  "x-alternatives": [
    {
      "$ref": "#/x-alt-definitions/Alt" // <==
    },
    {
      "$ref": "#/x-alt-definitions/Model 1" // <==
    }
  ]
}

It appears Joi.describe() is not associating the correct label when schema is:

Joi.alternatives().try(Joi.object({
    name: Joi.string().required()
}).label('alt1'), Joi.object({
    name: Joi.number().required()
}).label('alt2')).label('Alt')

@montumodi
Copy link
Author

@robmcguinness When are we planning to publish the change for Joi upgrade. At the moment our documentaion try it now feature is broken because of this example thingy.

@robmcguinness
Copy link
Collaborator

@montumodi no plans yet. Working through the broken test to understand if the x-alternatives logic that was in place before is valid anymore for Joi v14

@robmcguinness
Copy link
Collaborator

https://github.com/glennjones/hapi-swagger/releases/tag/v9.3.2 contains compatibility fix for Joi 14 and examples.

@laurilarjo
Copy link

v9.3.2 fixed the .example() issue for me and I was able to update joi to latest version. Thank you so much!

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

No branches or pull requests

4 participants