Skip to content

Conversation

stchr
Copy link
Contributor

@stchr stchr commented Aug 11, 2020

Q A
Bug fix? yes
New feature? no
BC breaks? yes
Deprecations? no
Tickets fixes #1969
License MIT
Doc PR api-platform/docs#...

This PR currently only urlencodes the colon : separator in schema names as this currently seems the only illegal char besides the allowed a-zA-Z0-9 _ . - in OpenAPI 3.0.

This PR urlencodes the whole name and additionally replacing / and ~ according to JSON Pointer Specification.

alanpoulain and others added 3 commits July 23, 2020 15:09
api-platform#3616)

* Changed depth and maxDepth handling for selfreferencing subresourceOperations.
Addresses: api-platform#2533.

* Use single name for subpath

* fix: address @rkopera comments

Co-authored-by: Clemens Pflaum <clemens.pflaum@yahoo.de>
@stchr stchr changed the title Encode definition names to be compliant with JSON Pointer Specification [core] Encode definition names to be compliant with JSON Pointer Specification Aug 11, 2020
@stchr stchr force-pushed the master branch 2 times, most recently from 1dbe47d to bd2f071 Compare August 11, 2020 10:32
@stchr stchr marked this pull request as ready for review August 11, 2020 19:39
@soyuka
Copy link
Member

soyuka commented Aug 12, 2020

behat tests failing

@stchr
Copy link
Contributor Author

stchr commented Aug 12, 2020

behat tests failing

@soyuka Done.

@soyuka
Copy link
Member

soyuka commented Aug 12, 2020

looks good, @dunglas could you check ?

@stchr
Copy link
Contributor Author

stchr commented Aug 12, 2020

@soyuka @dunglas As it comes out only the refs are affected (and not the schema definition names in general) there should be no more BC break and we could merge this in the 2.5 branch.
What do you think?

soyuka added 2 commits August 12, 2020 16:53
commit b5fcf46
Author: soyuka <soyuka@users.noreply.github.com>
Date:   Wed Aug 12 16:02:51 2020 +0200

    fix phpstan

commit 0cbc7e2
Author: Arnaud J <jabin@cikaba.com>
Date:   Sat Aug 8 16:35:09 2020 +0200

    :white_check_mark: Test API subresources with custom identifiers

commit d741950
Author: mahmood bazdar <mahmood.bazdar@gmail.com>
Date:   Mon Apr 27 15:29:01 2020 +0430

    Fixing error for none database identifiers Api ids
@dszwcz
Copy link

dszwcz commented Aug 19, 2020

@soyuka @dunglas it would be great to merge it :)

dunglas and others added 4 commits August 22, 2020 19:21
private function encodeDefinitionName(string $name): string
{
$entities = ['%2F', '%7E'];
$replacements = ['~1', '~0'];
Copy link
Member

Choose a reason for hiding this comment

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

Why is it necessary? IIRC only ~ and / must be encoded, not there URL encoded versions. Or am I missing something?

Copy link
Contributor Author

@stchr stchr Aug 26, 2020

Choose a reason for hiding this comment

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

Please have a look at #1969 (comment)

The characters / and ~ in node names must be encoded as ~1 and ~0 when used in a $ref, and other special characters must be percent-encoded.

@@ -95,7 +95,7 @@ Feature: Documentation support
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters" should have 6 elements

# Subcollection - check schema
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.responses.200.content.application/ld+json.schema.properties.hydra:member.items.$ref" should be equal to "#/components/schemas/RelatedToDummyFriend:jsonld-fakemanytomany"
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.responses.200.content.application/ld+json.schema.properties.hydra:member.items.$ref" should be equal to "#/components/schemas/RelatedToDummyFriend%3Ajsonld-fakemanytomany"
Copy link
Member

Choose a reason for hiding this comment

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

If we introduce a BC break, shouldn't we also change to a URL-safe character as separator to make the names more human-readable?

Copy link
Contributor Author

@stchr stchr Aug 26, 2020

Choose a reason for hiding this comment

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

Currently there should be no BC break as only the refs are affected, not the definition names itself.
And you prefered urlencode in #1969 (comment)

But sure we can switch to safe chars, if you like. Then we would have a BC break ;-) Which do you prefer? I guess . would be a good alternative to :?

@dunglas
Copy link
Member

dunglas commented Aug 26, 2020

Actually, as pointed out by @hkosova (#1969 (comment)), the generated identifiers are still invalid according to the OpenAPI spec: All the fixed fields declared above are objects that MUST use keys that match the regular expression: ^[a-zA-Z0-9\.\-_]+$.. We must use safe characters according to this regex instead of escaping.

@stchr
Copy link
Contributor Author

stchr commented Aug 26, 2020

Actually, as pointed out by @hkosova (#1969 (comment)), the generated identifiers are still invalid according to the OpenAPI spec: All the fixed fields declared above are objects that MUST use keys that match the regular expression: ^[a-zA-Z0-9\.\-_]+$.. We must use safe characters according to this regex instead of escaping.

@dunglas Good point, missed out OpenAPI 3.0 spec. Which character do you prefer from this regex? Would go with .?

@dszwcz
Copy link

dszwcz commented Aug 27, 2020

Actually, as pointed out by @hkosova (#1969 (comment)), the generated identifiers are still invalid according to the OpenAPI spec: All the fixed fields declared above are objects that MUST use keys that match the regular expression: ^[a-zA-Z0-9\.\-_]+$.. We must use safe characters according to this regex instead of escaping.

@dunglas Good point, missed out OpenAPI 3.0 spec. Which character do you prefer from this regex? Would go with .?

dot is ok for me

…ints-in-swagger

[Swagger] Fix that subresource endpoints do not override custom endpoints
api-platform#3676 - fixed subresource pagination support if primary resource has pagination disabled
@dunglas
Copy link
Member

dunglas commented Aug 27, 2020

. looks good to me too.

dunglas and others added 9 commits August 28, 2020 14:00
* fix: fix tests

* Remove phpspec/prophecy-phpunit

* Fix tests

* Fix PHPStan

* wip

* WIP

* Add PhpUnitPolyfillTrait

* Switch to simple-phpunit in Github Actions

* Use PHPUnit 9

* Try to use the good version of PHPUnit

* Use the master version of PHPUnit Bridge

* Remove PHPUnit from deps

* Use the files from Simple PHPUnit

* wip

* test

* test

* test

* improve phpstan config

* improve phpstan config

* Fix Behat

* Fix CI

* Fix some deprecations

* Fix build for Symfony 5.2

* Fix Mongo deprecations

* Fix AppVeyor build
* Add changelog for 2.5.7

* Update CHANGELOG.md

Co-authored-by: Alan Poulain <contact@alanpoulain.eu>

Co-authored-by: Alan Poulain <contact@alanpoulain.eu>
* 2.5:
  feat: bump JS deps
  Add changelog for 2.5.7 (api-platform#3691)
  fix: fix tests (api-platform#3688)
  Fix missing use statement (api-platform#3670)
  [MongoDB] Fix Behat tests (api-platform#3687)
  Fix missing Doctrine\Common\Persistence\ManagerRegistry class (api-platform#3684)
  [Swagger] Fix that subresource endpoints do not override custom endpoints
  api-platform#3676 - fixed subresource pagination support if primary resource has pagination disabled
* Use symfony/serializer >=4.4.9-5.0.9 to fix issues

symfony/symfony#34455
symfony/symfony#36601

* Lowest + legacy test suite missing git

* fix Symfony 5 router generate with reference type
…finition names to be compliant with OpenAPI 3.0
@stchr
Copy link
Contributor Author

stchr commented Sep 2, 2020

Messed up this PR 😞 , new and clean one is #3705
FYI @dunglas @soyuka

@stchr stchr closed this Sep 2, 2020
@stchr stchr deleted the master branch February 5, 2021 21:04
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.

Swagger documentation: Could not resolve reference
9 participants