theoomoregbee / sails-hook-swagger-generator

A tool to help generate Swagger specification documentation based on OAS 3.0 for Sails APIs
MIT License
78 stars 33 forks source link

Customization of blueprint routes on model does not work #77

Closed OscarMeier closed 4 years ago

OscarMeier commented 4 years ago

I'm not able to customize the blueprint route documentation: Neither by adding swagger JSDoc nor by adding the swagger object to the model (api/models/Foo.js):

/**
 *  @swagger
 *
 * /find:
 *    summary: Foo
 *    description: Bar
 */
swagger: {
    actions: {
      find: {
        summary: 'Foo',
        description: 'Bar',
      },
    },
  },

I dug into your code and found the referenced line. It's the line, where the paths get generated. The merged models contain the correct documentation (summary: 'Foo', description: 'Bar') but the models are not used in the generatePaths() function to override the blueprint templates. Did I overlook something or is this feature not implemented yet?

https://github.com/theoomoregbee/sails-hook-swagger-generator/blob/eafbed4acfce945103cbf06b776e9be669942916/lib/swagger-doc.ts#L95

danielsharvey commented 4 years ago

Found it - the model per-blueprint-action overrides where not being merged correctly. Bugfix shortly.

theoomoregbee commented 4 years ago

:tada: This issue has been resolved in version 3.2.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

danielsharvey commented 4 years ago

@OscarMeier Let us know how you get on. Thanks for finding this.

OscarMeier commented 4 years ago

@danielsharvey Thank you for the quick fix! The custom blueprint route documentation works as expected for the description and the summary. But I didn't figure out how to exclude an action. I tried to use the exclude option:

 * /add:
 *    exclude: true
 *
 * /populate:
 *    exclude: true
 */

I checked your code and found out that you just omit the exclude property:https://github.com/theoomoregbee/sails-hook-swagger-generator/blob/c407361355f0a3c117b01459084647a1d41db1bf/lib/generators.ts#L418 But the blueprint action documentation does not get removed, right?

I would propose to keep the exclude property in the clone and to add a condition below:

if (pathEntry.exclude) {
  return;
}
danielsharvey commented 4 years ago

@OscarMeier Let me look! It looks like I did not check the test data closely enough! (several changes had large effects and I must not have checked the test fixture closely enough).

danielsharvey commented 4 years ago

Found and fixed. Merging now.

Note that the exclude property is excluded as it is included within the swagger content but not valid OpenAPI and so excluded from the generated output.

theoomoregbee commented 4 years ago

:tada: This issue has been resolved in version 3.2.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

danielsharvey commented 4 years ago

@OscarMeier Let us know how you get on.

OscarMeier commented 4 years ago

@danielsharvey Thank you for resolving this issue! Everything works as expected.