redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

Join should put components back at the end of OAS files

Open steve-nay-sage opened this issue 3 years ago • 6 comments

Describe the bug I know that technically the order of sections in an OpenAPI file doesn't make a difference, but the output of the openapi join command now has components before paths. That's unexpected for those of us who are used to looking at files in which paths comes before components. It's machine-readable and functional either way, but not as human-readable as it used to be. I'm 99% certain that the join command used to output files with paths before components.

The "normal" way:

openapi:
info:
tags:
servers:
paths:
components:  <==

Current join output:

openapi:
info:
components:   <== 
tags:
servers:
paths:

Expected behavior My "wished for" behavior is that the join command would retain the order of the original OAS files in the output OAS file, but I realize that the different input files could have the sections in different orders. So my next-best wish is that join would go back to putting the components section at the end of the file, after paths.

openapi-cli Version(s) What version of openapi-cli are you using? beta.69

Node.js Version(s) What version of node.js are you using? 14.16.0

steve-nay-sage avatar Nov 18 '21 22:11 steve-nay-sage

Hi @steve-nay-sage, Could you confirm this is still the case? I've tried it several times couldn't reproduce this case.

SmoliyY avatar Jul 14 '22 10:07 SmoliyY

Now I see, this issue can be reproduced with this example. However seems like it's likely happening because of first definition not full and invalid. I am wondering if we want to join 2 definitions if one of them permanently not full or invalid - what do you think @RomanHotsiy @adamaltman

SmoliyY avatar Jul 15 '22 10:07 SmoliyY

I'm not sure. It can be valid and not full, right?

adamaltman avatar Jul 25 '22 21:07 adamaltman

Yes, but in case if we have '--lint' option enabled for the join command we do not exit in case if definition is invalid. I assume that in case of the --lint option we should not create result file and exit if there are any errors?

SmoliyY avatar Jul 26 '22 16:07 SmoliyY

I'm not sure about those above. I think what we should do is to sort top-level yaml keys before saving the output.

I think we should do it always (not only for join but for other commands as well) and do not keep the original document order.

What do you think?

RomanHotsiy avatar Jul 26 '22 18:07 RomanHotsiy

I think what we should do is to sort top-level yaml keys before saving the output.

It sounds reasonable and make sense. As for start we can go with such option.

I think we should do it always (not only for join but for other commands as well) and do not keep the original document order.

We probably will also need to apply this behaviour in the bundle command.

SmoliyY avatar Jul 28 '22 06:07 SmoliyY

@RomanHotsiy In what order should we sort the keys? Maybe we can use an order like here ? What to do with custom fields, add to the end of the file ?
@lornajane Perhaps you have some thoughts on this?

IgorKarpiuk avatar Apr 11 '23 14:04 IgorKarpiuk

I think the specification order of keys is a good idea, let's do that

lornajane avatar Apr 11 '23 15:04 lornajane

@IgorKarpiuk specification order makes sense in general but there is some issue.

Usually people put tags, security and externalDocs right after info section. And this makes a lot of sense to me.

I would use the following order.

openapi
info
jsonSchemaDialect
servers
security
tags
externalDocs
paths
webhooks
components

RomanHotsiy avatar Apr 12 '23 07:04 RomanHotsiy

@lornajane @adamaltman what do you think?

RomanHotsiy avatar Apr 12 '23 07:04 RomanHotsiy

I usually put tags last but that is probably a matter of taste! I'd be equally happy with the order suggested here

lornajane avatar Apr 12 '23 08:04 lornajane