Muka
Muka

Reputation: 1200

The documentation generated by open-api-catalog in ORDS get an error when opening in Swagger

The documentation generated by open-api-catalog brings some errors which cannot open in Swagger. Examples that present in the browser console:

duplicate mapping key

missed comma between flow collection entries

When we have a module in ORDS just with GET handlers, the documentation works fine in Swagger.

But when it's defined two or more POST or PUT handlers, we get a errors.

An example of the end-points definition:

begin  
   ORDS.DEFINE_MODULE(
      p_module_name    => 'so',
      p_base_path      => '/so/',
      p_items_per_page =>  15,
      p_status         => 'PUBLISHED',
      p_comments       => NULL);    
      
 ORDS.DEFINE_TEMPLATE(
      p_module_name    => 'so',
      p_pattern        => 'users/:id_user/op/:id_op',
      p_priority       => 0,
      p_etag_type      => 'HASH',
      p_etag_query     => NULL,
      p_comments       => '...');
  ORDS.DEFINE_HANDLER(
      p_module_name    => 'so',
      p_pattern        => 'users/:id_user/op/:id_op',
      p_method         => 'PUT',
      p_source_type    => 'plsql/block',
      p_items_per_page =>  0,
      p_mimes_allowed  => 'application/json',
      p_comments       => '...',
      p_source         => 
'BEGIN

   UPDATE USERS_OP
      SET id_papel_acesso_ops = :id_papel_acesso_ops
        , dt_alteracao = :dt_alteracao
        , cd_usuario_alteracao = :cd_usuario_alteracao
    WHERE id_op = :id_op
      AND id_user = :id_user;

    COMMIT;

    :status_code := 204; -- No Content

EXCEPTION    
    WHEN OTHERS THEN
        ROLLBACK;
        :status_code := 400; 
        HTP.PRN(''{"error": "'' || SQLERRM || ''"}'');

END;'
      );
      
  ORDS.DEFINE_HANDLER(
      p_module_name    => 'so',
      p_pattern        => 'users/:id_user/op/:id_op',
      p_method         => 'POST',
      p_source_type    => 'plsql/block',
      p_items_per_page =>  0,
      p_mimes_allowed  => 'application/json',
      p_comments       => '...',
      p_source         => 
'BEGIN

   INSERT INTO USERS_OP (id_papel_acesso_ops, id_user, id_op) VALUES(:id_papel_acesso_ops, :id_user, :id_op);

    COMMIT;

    :status_code := 204; -- No Content

EXCEPTION    
    WHEN OTHERS THEN
        ROLLBACK;
        :status_code := 400; 
        HTP.PRN(''{"error": "'' || SQLERRM || ''"}'');

END;'
      );      
    end;
    /

NOTE 1: Updated the example to two handler (POST and PUT)

NOTE 2: this description changed a little considering the initial version, to make the question more general.

Upvotes: 0

Views: 467

Answers (1)

thatjeffsmith
thatjeffsmith

Reputation: 22412

Using ORDS 21.4 and creating a module to hold your template/handler, here's what I get.

REST Definition with ORDS API, module named 'so':

 begin  
   ORDS.DEFINE_MODULE(
      p_module_name    => 'so',
      p_base_path      => '/so/',
      p_items_per_page =>  15,
      p_status         => 'PUBLISHED',
      p_comments       => NULL);    
      
 ORDS.DEFINE_TEMPLATE(
      p_module_name    => 'so',
      p_pattern        => 'users/:id_user/op/:id_op',
      p_priority       => 0,
      p_etag_type      => 'HASH',
      p_etag_query     => NULL,
      p_comments       => '...');
  ORDS.DEFINE_HANDLER(
      p_module_name    => 'so',
      p_pattern        => 'users/:id_user/op/:id_op',
      p_method         => 'PUT',
      p_source_type    => 'plsql/block',
      p_items_per_page =>  0,
      p_mimes_allowed  => 'application/json',
      p_comments       => '...',
      p_source         => 
'BEGIN

   UPDATE USERS_OP
      SET id_papel_acesso_ops = :id_papel_acesso_ops
        , dt_alteracao = :dt_alteracao
        , cd_usuario_alteracao = :cd_usuario_alteracao
    WHERE id_op = :id_op
      AND id_user = :id_user;

    COMMIT;

    :status_code := 204; -- No Content

EXCEPTION    
    WHEN OTHERS THEN
        ROLLBACK;
        :status_code := 400; 
        HTP.PRN(''{"error": "'' || SQLERRM || ''"}'');

END;'
      );
    end;
    /
    

Ask for the OpenData {json}

{
    "swagger": "2.0",
    "info": {
        "title": "ORDS generated API for so",
        "version": "1.0.0"
    },
    "host": "pvqhdhmzqnn1hi4-tjsatp.adb.us-ashburn-1.oraclecloudapps.com",
    "basePath": "/ords/admin/so",
    "schemes": [
        "https"
    ],
    "produces": [
        "application/json"
    ],
    "paths": {
        "/users/{id_user}/op/{id_op}": {
            "put": {
                "description": "...",
                "responses": {
                    "200": {
                        "description": "The successfully updated record.",
                        "schema": {
                            "type": "object",
                            "properties": {}
                        }
                    },
                    "201": {
                        "description": "The successfully created record.",
                        "schema": {
                            "type": "object",
                            "properties": {}
                        }
                    }
                },
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "name": "id_op",
                        "in": "path",
                        "required": true,
                        "type": "string",
                        "description": "implicit",
                        "pattern": "^[^/]+$"
                    },
                    {
                        "name": "id_user",
                        "in": "path",
                        "required": true,
                        "type": "string",
                        "description": "implicit",
                        "pattern": "^[^/]+$"
                    },
                    {
                        "name": "payload",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/so_ITEM"
                        }
                    }
                ]
            }
        }
    },
    "definitions": {
        "STRING": {
            "type": "string"
        },
        "so_ITEM": {
            "properties": {
                "id_papel_acesso_ops": {
                    "type": "string"
                },
                "dt_alteracao": {
                    "type": "string"
                },
                "cd_usuario_alteracao": {
                    "type": "string"
                },
                "status_code": {
                    "type": "string"
                }
            }
        }
    }
}

Feed THAT into editor.swagger.io - enter image description here

Upvotes: 0

Related Questions