cebe / php-openapi

Read and write OpenAPI yaml/json files and make the content accessible in PHP objects.
MIT License
466 stars 88 forks source link

Access extension properties like `x-foo-bar` as `x_foo_bar` #88

Open rv1971 opened 3 years ago

rv1971 commented 3 years ago

The OpenAPI specification allows for extension properties whose names must start with x-, citing x-internal-id as an example. Since such a property cannot be accessed as $obj->x-internal-id, the present commit translates the name so that it can be accessed as $obj->x_internal_id.

cebe commented 3 years ago

Since such a property cannot be accessed as $obj->x-internal-id

it is possible to access these like $obj->{'x-internal-id'}. Converting the name is a bit arbitrary, need to think about it. A better solution might be to implement ArrayAccess interface to allow $obj['x-internal-id'].

Linking for reference: http://spec.openapis.org/oas/v3.0.3#specification-extensions

cebe commented 2 years ago

realted to #121