Skip to content

Conversation

Wojdylak
Copy link
Contributor

@Wojdylak Wojdylak commented Oct 6, 2023

Q A
Branch? 3.1
Tickets N/A
License MIT

@Wojdylak Wojdylak force-pushed the miss-item-uri-template branch from ca926af to f194c5a Compare October 6, 2023 10:56
<xsd:attribute type="xsd:boolean" name="openapi"/>
<xsd:attribute type="xsd:positiveInteger" name="priority"/>
<xsd:attribute type="xsd:string" name="name"/>
<xsd:attribute type="xsd:string" name="itemUriTemplate"/>
Copy link
Member

Choose a reason for hiding this comment

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

as this is not declared on every operation I'm not sure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I got an error when I used itemUriTemplete. Element '{https://api-platform.com/schema/metadata/resources-3.0}operation', attribute 'itemUriTemplate': The attribute 'itemUriTemplate' is not allowed.

Copy link
Contributor

Choose a reason for hiding this comment

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

itemUriTemplate is only available on GetCollection and Post operations. But I'm not sure it's possible to handle such difference with XML schema...

A solution would be to allow this attribute on XML and YAML schemas, and add a specific validation on XmlResourceExtractor and YamlResourceExtractor services to ensure this attribute is only set on a GetCollection or Post operation, otherwise throw an error. The XmlExtractorTest and YamlExtractorTest should help to test this behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: apparently, I already did a similar check in resource extractors 😃
https://github.com/api-platform/core/blob/3.1/src/Metadata/Extractor/XmlResourceExtractor.php#L387-L389
https://github.com/api-platform/core/blob/3.1/src/Metadata/Extractor/YamlResourceExtractor.php#L323-L325

Throwing an exception if the operation does not match could improve the DX instead of just ignoring the key (PR in progress).

@soyuka soyuka merged commit eebc7c5 into api-platform:3.1 Oct 9, 2023
@soyuka
Copy link
Member

soyuka commented Oct 9, 2023

let's merge that for now, I'd like @vincentchalamon insights on this

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants