You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I add two methods on swagger3.py to change the $ref (recursively) with the respective value (without change if it is a schema) with that code:
`
def has_ref(self, obj):
if isinstance(obj, dict):
if '$ref' in obj:
return True
return any(self.has_ref(v) for v in obj.values())
elif isinstance(obj, list):
return any(self.has_ref(item) for item in obj)
return False
def resolve_ref(self, obj, parent_key=None):
if isinstance(obj, dict):
if '$ref' in obj.keys() and parent_key != 'schema':
ref_path = obj['$ref'].split('/')[1:]
ref_data = self.data
for path in ref_path:
ref_data = ref_data.get(path, {})
# check if there is more $ref.
if self.has_ref(ref_data):
resolved_data = self.resolve_ref(ref_data)
else:
resolved_data = ref_data
# Change the obj(ref)
return resolved_data
else:
for key, value in list(obj.items()):
obj[key] = self.resolve_ref(value, key)
elif isinstance(obj, list):
return [self.resolve_ref(item, parent_key) for item in obj]
return obj`
This means that the above error no longer occurs, but now it generates an exception in create_node_type_from_schema(), apparently just works with the v1 OAS specification:
ERROR:oas2tosca.swagger:ResourceCatalog_Create: creating node type without group version kind
Edit: I also tried with the v5 (attached), these use a OAS v3. The error change a litle bit. The attached file is in fact a YAML, I changed to JSON to be able to attach here.
The text was updated successfully, but these errors were encountered:
TMF634-Resource_Catalog_Management-v5.0.0.oas.json
I've been trying to convert LOAS from an API without success. Specifically the TMF634 v4 that I attach here.
The first errors I received were related to oas2tosca not handling $ref in some points in the yaml:
oas2tosca --input C:\oas2tosca\TMF634-Resource_Catalog_Management-v5.0.0.oas.yaml --output C:\oas2tosca\ --debug DEBUG:oas2tosca.__main__:Input file: C:\oas2tosca\TMF634-Resource_Catalog_Management-v5.0.0.oas.yaml DEBUG:oas2tosca.__main__:TOSCA output directory: C:\oas2tosca\ DEBUG:oas2tosca.__main__:Converting Swagger 3.0 file DEBUG:oas2tosca.swagger:Processing Paths Object DEBUG:oas2tosca.swagger:'/exportJob' parameters: ERROR:oas2tosca.__main__:Error converting 'C:\oas2tosca\TMF634-Resource_Catalog_Management-v5.0.0.oas.yaml': 'content'
I add two methods on swagger3.py to change the $ref (recursively) with the respective value (without change if it is a schema) with that code:
`
def has_ref(self, obj):
if isinstance(obj, dict):
if '$ref' in obj:
return True
return any(self.has_ref(v) for v in obj.values())
elif isinstance(obj, list):
return any(self.has_ref(item) for item in obj)
return False
def resolve_ref(self, obj, parent_key=None):
if isinstance(obj, dict):
if '$ref' in obj.keys() and parent_key != 'schema':
ref_path = obj['$ref'].split('/')[1:]
ref_data = self.data
for path in ref_path:
ref_data = ref_data.get(path, {})
# check if there is more $ref.
if self.has_ref(ref_data):
resolved_data = self.resolve_ref(ref_data)
else:
resolved_data = ref_data
# Change the obj(ref)
return resolved_data
else:
for key, value in list(obj.items()):
obj[key] = self.resolve_ref(value, key)
elif isinstance(obj, list):
return [self.resolve_ref(item, parent_key) for item in obj]
return obj`
This means that the above error no longer occurs, but now it generates an exception in create_node_type_from_schema(), apparently just works with the v1 OAS specification:
ERROR:oas2tosca.swagger:ResourceCatalog_Create: creating node type without group version kind
oas: https://github.com/tmforum-apis/TMF634_ResourceCatalog/blob/master/TMF634-ResourceCatalog-v4.0.0.swagger.json
Edit: I also tried with the v5 (attached), these use a OAS v3. The error change a litle bit. The attached file is in fact a YAML, I changed to JSON to be able to attach here.
The text was updated successfully, but these errors were encountered: