Skip to content

support a per-function @noCbSwagger attribute #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

davidAtInleague
Copy link

@davidAtInleague davidAtInleague commented Sep 11, 2023

the presence of this attribute prevents the inclusion of the function's associated documentation from ending up in swagger docs

Description

completes #42

Type of change

  • Improvement

Checklist

  • My code follows the style guidelines of this project cfformat
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

the presence of this attribute prevents the inclusion of the
function's associated documentation from ending up in
swagger docs
Copy link
Collaborator

@jclausen jclausen left a comment

Choose a reason for hiding this comment

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

Looks great @davidAtInleague ! A couple of cleanup items and then I will merge this a bump a patch.

@@ -324,6 +339,11 @@ component accessors="true" threadsafe singleton {
}
}

if ( path.count() == 0 ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use boolean evaluation here, per Ortus Coding Standards

Copy link
Author

Choose a reason for hiding this comment

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

addressed

// then do not expose this function to swagger docs.
//
if ( !isNull( arguments.handlerMetadata ) ) {
var maybeNull_metaData = getFunctionMetadata( handlerMetadata = arguments.handlerMetadata, functionName = lCase( actions[ methodName ] ) );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just call this var functionMetadata

Copy link
Author

Choose a reason for hiding this comment

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

addressed

* return true if the metadata represents a function marked "noCbSwagger"
*/
private boolean function isAnnotatedWithTruthyNoCbSwaggerAttribute( required struct functionMetadata ) {
if ( !structKeyExists( functionMetadata, "noCbSwagger" ) ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's call this function metadata cbSwagger, check for its existence, and then look for a boolean false. This can open up additional inclusions in the future by using cbSwagger or cbSwagger=true on a function or component. When we implement this, we could then do discovery of an entire site without includes/excludes by simply using the component/function MD

Copy link
Collaborator

Choose a reason for hiding this comment

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

So your function annotation would become:

function myFunction() cbSwagger=false{...}

or

/**
* @cbswagger false
**/
function myFunction(){...}

Copy link
Author

Choose a reason for hiding this comment

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

addressed

return false;
}

if ( trim( functionMetadata.noCbSwagger ) == "" ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can simplify the conditionals here with a ternary here:

return  !structKeyExists( functionMetadata, "cbSwagger" )
             ? false
             :  !functionMetadata.cbswagger.len() 
                    ||  ( 
                            isValid( "boolean", functionMetadata.noCbSwagger ) && functionMetadata.noCbSwagger 
                         );

Copy link
Author

Choose a reason for hiding this comment

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

addressed

/**
* return true if the metadata represents a function marked "noCbSwagger"
*/
private boolean function isAnnotatedWithTruthyNoCbSwaggerAttribute( required struct functionMetadata ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's rename this method to isCbSwaggerEnabled

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually since this is within the scope of the parser, let's just call this isDocumentationEnabled. Then we could hook in to other exclusions, as necessary, down the road.

Copy link
Author

Choose a reason for hiding this comment

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

addressed

@davidAtInleague
Copy link
Author

I tried to run cfformat but get the following, I'm not sure what the issue is here:

CommandBox:cbSwagger> run-script format

Running package script [format].
> cfformat run helpers,models,test-harness/tests/,ModuleConfig.cfc --overwrite
 × | Formatting files...
   |----------------------------------
   | /home/david/ortus/cbSwagger/ModuleConfig.cfc
   | /home/david/ortus/cbSwagger/models/RoutesParser.cfc
   | /home/david/ortus/cbSwagger/test-harness/tests/Application.cfc
   | /home/david/ortus/cbSwagger/test-harness/tests/specs/RoutesParserTest.cfc
   |----------------------------------
Files formatted: 0
The following files were unable to be formatted:


  /home/david/ortus/cbSwagger/ModuleConfig.cfc
  /home/david/ortus/cbSwagger/models/RoutesParser.cfc
  /home/david/ortus/cbSwagger/test-harness/tests/Application.cfc
  /home/david/ortus/cbSwagger/test-harness/tests/specs/RoutesParserTest.cfc



ERROR (5.9.1+00767)

Package script returned failing exit code (1)

Failing script: format

CommandBox:cbSwagger> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants