Comments (11)
Am I understanding the main goal is to return a custom array of objects?
from cakephp-swagger-bake.
I'd have to probably dig into this one for a bit. Off the top of my head your immediate workarounds (if this indeed is not possible) are:
Events: https://github.com/cnizzardini/cakephp-swagger-bake#event-system
CustomSchemaInterface: https://github.com/cnizzardini/cakephp-swagger-bake/blob/master/docs/attributes.md#schema
from cakephp-swagger-bake.
Am I understanding the main goal is to return a custom array of objects?
Yes exactly. I think it's the only thing missing to get full flexibility in documenting custom code. I'll see if I can do something with Events and CustomSchemaInterface.
Thanks!
from cakephp-swagger-bake.
@ChrisB85 did this solve your needs?
from cakephp-swagger-bake.
Unfortunately not. I tried to use events to modify the Swagger object but at some point I realized that It's just bad (to complicated) solution if I need to document many endpoints that way.
from cakephp-swagger-bake.
Yeah I agree, I think your use-case is reasonable. I'll note this as a feature request.
from cakephp-swagger-bake.
I think I've actually had this need in one of my applications, but out of sheer laziness have just left that portion of the schema not documented well.
from cakephp-swagger-bake.
I'm curious @ChrisB85, if for a more reasonable short-term work around, can you use a mixture of $ref
and OpenApiSchemaProperty. Something like this:
OpenAPI Schema:
#[OpenApiSchema(visibility: OpenApiSchema::VISIBLE_ALWAYS)]
class ArticleProperties extends DataTransferObject
{
#[OpenApiSchemaProperty(name: 'id', type: 'string', format: 'int32', example: '3214')]
public string $id;
#[OpenApiSchemaProperty(name: 'name', type: 'string', example: 'Some name')]
public string $name;
}
Controller:
#[OpenApiResponse(schemaType: 'array' ,ref: '#/components/schemas/ArticlesCollection')]
public function findArticles()
{
// controller action code...
}
OpenAPI YAML:
components:
schemas:
ArticlesCollection:
properties:
data:
items:
type: object
allOf:
- $ref: '#/components/schemas/ArticleProperties'
type: array
I think something like that may be possible. The idea being, document the object in your DTO, use OpenAPI YAML to document that its part of collection and then reference the YAML ref in your controller action.
from cakephp-swagger-bake.
Thank you very much, I will try it :)
from cakephp-swagger-bake.
Sorry for a delay, today I finally had some time to use your sugesstion. Unfortunatelly the ArticleProperties schema is not included into swagger.json so I get result like:
I think I need some clever way to include it.
from cakephp-swagger-bake.
Ah this makes sense, I think its only adding schemas when there is an associated route. You can try adding this attribute and setting visibility, but I am not sure it will work. We are in slightly uncharted territory:
https://github.com/cnizzardini/cakephp-swagger-bake/blob/master/docs/attributes.md#openapischema
from cakephp-swagger-bake.
Related Issues (20)
- Support for MySQL json field type HOT 7
- OpenApiResponse annotation doesn't work properly with schemaType: 'array' and ref. HOT 4
- OpenApiSchemaProperty(name: 'propert_name', type: 'array') not working
- Logic of Configuration class HOT 11
- Feature Query: is it possible to hide model properties? HOT 4
- Backport fix from 5.x branch
- Too few arguments to function Cake\View\Exception\MissingTemplateException::__construct(), 0 passed HOT 4
- Throw tags taking precedence over OpenApiResponse attribute
- collection generation HOT 3
- Undefined array key "securitySchemes" in Cakaphp 4.15 version HOT 2
- Undefined array key "securitySchemes" HOT 10
- Cannot make controller working HOT 3
- Prevent loading associations in ApiResponse(associations: $var) HOT 10
- Up-port 2.5.9 to 3.0.1
- [InvalidArgumentException] Invalid yml: `/config/swagger.yml
- SwaggerBake Schema and SwaggerBake Routes executes even when hotReload is false HOT 6
- Hidden properties displaying in OpenAPI Schema
- Invalid Enum Syntax
- Missing schema - Cakephp 5 with Plugins HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cakephp-swagger-bake.