Giter Site home page Giter Site logo

Comments (11)

cnizzardini avatar cnizzardini commented on June 17, 2024

Am I understanding the main goal is to return a custom array of objects?

from cakephp-swagger-bake.

cnizzardini avatar cnizzardini commented on June 17, 2024

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.

ChrisB85 avatar ChrisB85 commented on June 17, 2024

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.

cnizzardini avatar cnizzardini commented on June 17, 2024

@ChrisB85 did this solve your needs?

from cakephp-swagger-bake.

ChrisB85 avatar ChrisB85 commented on June 17, 2024

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.

cnizzardini avatar cnizzardini commented on June 17, 2024

Yeah I agree, I think your use-case is reasonable. I'll note this as a feature request.

from cakephp-swagger-bake.

cnizzardini avatar cnizzardini commented on June 17, 2024

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.

cnizzardini avatar cnizzardini commented on June 17, 2024

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.

ChrisB85 avatar ChrisB85 commented on June 17, 2024

Thank you very much, I will try it :)

from cakephp-swagger-bake.

ChrisB85 avatar ChrisB85 commented on June 17, 2024

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:
image
I think I need some clever way to include it.

from cakephp-swagger-bake.

cnizzardini avatar cnizzardini commented on June 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.