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

Add support for generating property schema with Choice restriction #4162

Merged

Conversation

norkunas
Copy link
Contributor

Q A
Branch? 2.6
Bug fix? yes
New feature? no
Deprecations? no
Tickets N/A
License MIT
Doc PR N/A

Add a PropertySchemaChoiceRestriction to transform Choice validation constraint into these schemas:

@Assert\Choice(choices={"choice1", "choice2"})

{
  "enum": ["choice1", "choice2"]
}

@Assert\Choice(choices={"choice1", "choice2"}, multiple=true)

{
  "type": "array",
  "items": { "enum": ["choice1", "choice2"] }
}

@Assert\Choice(choices={"choice1", "choice2", "choice3", "choice4"}, multiple=true, min=2, max=4)

{
  "type": "array",
  "items": { "enum": ["choice1", "choice2", "choice3", "choice4"] },
  "minItems": 2,
  "maxItems": 4
}

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

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

Nice! This should also target main

@norkunas norkunas force-pushed the property-schema-choice-restriction branch 2 times, most recently from 4827efc to ed85a5e Compare March 25, 2021 13:02
@norkunas norkunas changed the base branch from 2.6 to main March 25, 2021 13:02
@soyuka soyuka force-pushed the property-schema-choice-restriction branch 2 times, most recently from 906d90d to d40af55 Compare March 25, 2021 13:20
@norkunas norkunas force-pushed the property-schema-choice-restriction branch 2 times, most recently from 5075f32 to fa7f475 Compare March 25, 2021 13:25
@norkunas norkunas changed the title Fix generating property schema with Choice restriction Add support for generating property schema with Choice restriction Mar 25, 2021
@norkunas norkunas force-pushed the property-schema-choice-restriction branch 7 times, most recently from 1546b46 to 6c1662a Compare March 26, 2021 10:54
@norkunas norkunas force-pushed the property-schema-choice-restriction branch from 6c1662a to 2a5e21f Compare March 26, 2021 14:15
@alanpoulain alanpoulain merged commit b7a980e into api-platform:main Mar 26, 2021
@alanpoulain
Copy link
Member

Thank you very much!

@norkunas norkunas deleted the property-schema-choice-restriction branch March 26, 2021 17:49
@bouffa
Copy link

bouffa commented Apr 22, 2022

I am trying to make this work with Api Platform Admin module with no luck.
I inspected the docs.jsonld served by the api, and there is no enum specified. However, I can see the enum in the docs.json. Am I missing something?
Thanks

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.

4 participants