Skip to content

Commit

Permalink
Path parameters as reference, close 365
Browse files Browse the repository at this point in the history
  • Loading branch information
javiertuya committed Feb 18, 2025
1 parent 54a9722 commit a3d0de4
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static boolean oaBoolean(Boolean value) {
* Gets the object name in a ref in a form like #/components/schemas/name
*/
public static String getNameFromRef(String ref) {
// Because we can find other names like paths in #/components/parameters/name
// Because we can find other names under components
// the general procedure is splitting the name and get the last value
String[] split = ref.split("/");
return split[split.length - 1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ private void addEntityPath(String method, String requestOrResponse, String oaKey
entityPath.method = method;
entityPath.path = oaKey;
entityPath.oaParams = operation.getParameters();
// check empty parameters (maybe because a ref was not found)
for (Parameter oaParam : ModelUtil.safe(entityPath.oaParams))
if (oaParam.getIn() == null)
oaLogger.warn(log, "Parameter with name: {}, ref: {} has no 'in' definition", oaParam.getName(), oaParam.get$ref());
this.entityPaths.add(entityPath);
}
}
Expand Down Expand Up @@ -208,7 +212,7 @@ public List<Parameter> getPathParams(String entityName) {
for (EntityPath entityPath : entityPaths.get(entityName)) {
if (entityPath.entityName.equalsIgnoreCase(entityName) && entityPath.method.equals(POST)) {
for (Parameter oaParam : ModelUtil.safe(entityPath.oaParams)) {
if (oaParam.getIn().equals("path")) {
if (oaParam.getIn() != null && oaParam.getIn().equals("path")) {
oaParams.add(oaParam);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
"uid" : "true",
"notnull" : "true"
} ]
}, {
"name" : "masterref",
"entitytype" : "table",
"attributes" : [ {
"name" : "id",
"datatype" : "string",
"uid" : "true",
"notnull" : "true"
} ]
}, {
"name" : "DetailPost",
"entitytype" : "table",
Expand All @@ -53,10 +62,16 @@
"notnull" : "true",
"rid" : "Master.id",
"ridname" : "fk_DetailPost_MasterId"
}, {
"name" : "MasterRef_id",
"datatype" : "int",
"notnull" : "true",
"rid" : "masterref.id",
"ridname" : "fk_DetailPost_MasterRef_id"
} ],
"ddls" : [ {
"command" : "post",
"query" : "/detailpost/{master_id}/{masternot}/{id}/{Master2Id}/{MasterId}"
"query" : "/detailpost/{master_id}/{masternot}/{id}/{Master2Id}/{MasterId}/{referenced}"
} ]
}, {
"name" : "DetailPut",
Expand Down
12 changes: 12 additions & 0 deletions tdrules-client-oa/src/test/resources/bmk/oa-path-params.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
"notnull" : "true",
"rid" : "Master.id",
"ridname" : "fk_DetailPost_with_rid"
}, {
"name" : "ref_with_rid",
"datatype" : "int",
"notnull" : "true",
"rid" : "Master.ref_with_rid",
"ridname" : "fk_DetailPost_ref_with_rid"
}, {
"name" : "ref_with_rid2",
"datatype" : "int",
"notnull" : "true",
"rid" : "Master.ref_with_rid2",
"ridname" : "fk_DetailPost_ref_with_rid2"
}, {
"name" : "with_rid_and_uid",
"datatype" : "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ info:
resolved in post
camel/snake
case convention betweeen parameter and entity match/do not match
master: two resolved different/same master)
master: two resolved different/same master
reusable parameter
unresolved post: to id/none
resolved in put (should not resolve)
paths:
/detailpost/{master_id}/{masternot}/{id}/{Master2Id}/{MasterId}:
/detailpost/{master_id}/{masternot}/{id}/{Master2Id}/{MasterId}/{referenced}:
post:
parameters:
- in: path
Expand All @@ -33,6 +34,11 @@ paths:
name: MasterId
schema:
type: int
- $ref: "#/components/parameters/masterref_id"
- in: path
name: MasterRef_id
schema:
type: int
requestBody:
content:
application/json:
Expand All @@ -51,6 +57,12 @@ paths:
schema:
$ref: "#/components/schemas/DetailPut"
components:
parameters:
referenced:
in: path
name: MasterRef_id
schema:
type: int
schemas:
Master:
properties:
Expand All @@ -64,6 +76,10 @@ components:
properties:
id:
type: string
masterref:
properties:
id:
type: string
DetailPost:
properties:
id:
Expand Down
34 changes: 29 additions & 5 deletions tdrules-client-oa/src/test/resources/inp/oa-path-params.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ info:
version: 1.0.0
title: >
Path parameters:
Should add to the model those parameters that are rid in a POST operation
Should add a rid to the model for those path parameters that have a rid in a POST operation
- primitive: with rid (add), with rid and uid (add), with uid only, without any
- with ref: key matches name / does not match / ref definition not found (ignore)
- non primitive: object, array
- is query parameter
- is last parameter
The parameter is in a PUT (ignore)
Ignored
- is query parameter
- the parameter is in a PUT
paths:
/detailpost/{master_id}:
post:
Expand All @@ -18,7 +20,8 @@ paths:
x-fk: Master.id
schema:
type: int
# Not requiring the resulting model be consistent
# with rid and uid is last param

- in: path
name: uidOnly
x-pk: true
Expand All @@ -28,6 +31,13 @@ paths:
name: noRidNoUid
schema:
type: int

# reusable params
- $ref: "#/components/parameters/ref_with_rid"
- $ref: "#/components/parameters/ref_no_match_name"
- $ref: "#/components/parameters/ref_not_found"

# non primitive params
- in: path
x-fk: other.id
name: objectParam
Expand All @@ -48,9 +58,10 @@ paths:
x-fk: other3.id
schema:
type: int

- in: path
name: with_rid_and_uid
x-fk: Master.id2
x-fk: Master.id2 # Not requiring the existence of referenced id
x-pk: true
schema:
type: string
Expand All @@ -73,6 +84,19 @@ paths:
schema:
$ref: "#/components/schemas/DetailPut"
components:
parameters:
ref_with_rid:
in: path
name: ref_with_rid
x-fk: Master.ref_with_rid
schema:
type: int
ref_no_match_name:
in: path
name: ref_with_rid2
x-fk: Master.ref_with_rid2
schema:
type: int
schemas:
Master:
properties:
Expand Down

0 comments on commit a3d0de4

Please # to comment.