Skip to content
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

oas v3 it is not working properly #1

Open
rivaldoeno opened this issue Dec 11, 2023 · 1 comment
Open

oas v3 it is not working properly #1

rivaldoeno opened this issue Dec 11, 2023 · 1 comment

Comments

@rivaldoeno
Copy link

rivaldoeno commented Dec 11, 2023

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.

@lauwers
Copy link
Collaborator

lauwers commented Dec 12, 2023

Thanks for pointing this out @rivaldoeno . I'll look into this over the next couple of days.

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

No branches or pull requests

2 participants