Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Handling map values that are lists #47

Open
segfir opened this issue Apr 23, 2017 · 0 comments
Open

Handling map values that are lists #47

segfir opened this issue Apr 23, 2017 · 0 comments

Comments

@segfir
Copy link

segfir commented Apr 23, 2017

In my fix-arrays-in-map branch I have a file called maps.yaml which causes some problems for swagger-parser.

I came across this problem when I started using swagger-tester to test the API generated by Swashbuckle (a C# library to auto-generate swagger api from class definitions). In that, I specified a series of classes which generated the yaml similar to what you see in maps.yaml. Even though the file is slightly different from what was auto-generated, the takeway is the use of properties instead of additionalProperties.

The two things I noticed swagger-parser struggling with were:

  1. The expected value of an entry in a map is meant to be a list but is instead flattened to a single object.
  2. The entire return result which is meant to be an object is turned into a list.

If my yaml file is indeed correct and should be returning the data I've specified in the tests I've added. The potential fix is in https://github.com/vinnier/swagger-parser/commit/df47a883da4bdf1f617d7e97b5b93ace9f9ca4af.

My biggest concern with my change is the code I've commented out. I expect a list to be returned from that function but it's specifically coded against and reinforced by a comment. I'm hoping @jfinkhaeuser can comment on this and possibly provide an example of a definition that would break my proposed change.

EDIT: This whole section needs a rethink

Also, while trying to fix this problem I noticed one of the current tests may be incorrect. If I understand the definition in the test correctly, the assert on line 125 should be checking for an object, not a list.

I haven't created a pull request because I'm not convinced I'm writing my yaml correctly. It validates without any problems but the expected return value swagger-parser generates is different to what I expected. If someone could critique my proposed changes and provide any input/guidance, that would be great.

Thanks.

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

No branches or pull requests

1 participant