Skip to content

Commit

Permalink
Fix issue with data type when the path segment has parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
lnash94 committed Sep 27, 2023
1 parent 22a6f14 commit 27ed209
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,18 @@ public void testsRefParamsInOpenAPIV31() throws IOException, BallerinaOpenApiExc
CommonTestFunctions.compareGeneratedSyntaxTreewithExpectedSyntaxTree(
"parameter_with_ref_v31.bal", syntaxTree);
}
}

@Test(description = "Tests for path segments has parameters with extension")
public void testsForPathSegmentHasExtensionType() throws IOException, BallerinaOpenApiException {
Path definitionPath = RES_DIR.resolve("swagger/multiPathParamWithExtensionType.yaml");
OpenAPI openAPI = GeneratorUtils.getOpenAPIFromOpenAPIV3Parser(definitionPath);
OASServiceMetadata oasServiceMetadata = new OASServiceMetadata.Builder()
.withOpenAPI(openAPI)
.withFilters(filter)
.build();
BallerinaServiceGenerator ballerinaServiceGenerator = new BallerinaServiceGenerator(oasServiceMetadata);
syntaxTree = ballerinaServiceGenerator.generateSyntaxTree();
CommonTestFunctions.compareGeneratedSyntaxTreewithExpectedSyntaxTree(
"multiPathParamWithExtensionType.bal", syntaxTree);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import ballerina/http;

listener http:Listener ep0 = new (80, config = {host: "petstore.openapi.io"});

service /v1 on ep0 {
# Info for a specific pet
#
# + spreadsheetId - The id of the pet to retrieve
# + sheetidCopyto - The id of the pet to retrieve
# + return - returns can be any of following types
# http:Ok (Expected response to a valid request)
# http:Response (unexpected error)
resource function get v4/spreadsheets/[int spreadsheetId]/sheets/[string sheetidCopyto]() returns http:Ok|http:Response|error {
if !sheetidCopyto.endsWith(":copyTo") {
return error("bad URL");
}
string sheetId = sheetidCopyto.substring(0, sheetidCopyto.length() - 6);
}
# Get the details of the specified field
#
# + idJson - Field ID
# + return - Successful response
resource function get 'field/[string idJson]() returns http:Ok|error {
if !idJson.endsWith(".json") {
return error("bad URL");
}
string id = idJson.substring(0, idJson.length() - 4);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: OpenApi Petstore
license:
name: MIT
servers:
- url: http://petstore.{host}.io/v1
description: The production API server
variables:
host:
default: openapi
description: this value is assigned by the service provider

tags:
- name: pets
description: Pets Tag
- name: list
description: List Tag

paths:
/v4/spreadsheets/{spreadsheetId}/sheets/{sheetId}:copyTo:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: spreadsheetId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: integer
- name: sheetId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: integer
responses:
'200':
description: Expected response to a valid request
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/field/{id}.json:
get:
tags:
- Field
operationId: getFieldById
description: Get the details of the specified field
parameters:
- description: Field ID
in: path
name: id
schema:
type: number
format: double
required: true
responses:
'200':
description: Successful response
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
type:
type: string
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private static void extractPathParameterDetails(Operation operation, List<Node>
// TypeDescriptor
BuiltinSimpleNameReferenceNode builtSNRNode = createBuiltinSimpleNameReferenceNode(
null,
parameter.getSchema() == null ?
parameter.getSchema() == null || hasSpecialCharacter ?
createIdentifierToken(STRING) :
createIdentifierToken(paramType));
IdentifierToken paramName = createIdentifierToken(
Expand Down

0 comments on commit 27ed209

Please sign in to comment.