smithy4s icon indicating copy to clipboard operation
smithy4s copied to clipboard

Allow to exclude nested namespaces

Open ghostbuster91 opened this issue 1 year ago • 8 comments

When generating scala classes from smithy model we often need to exclude certain namespaces due to various reasons.

For that we were using --exclude-ns option in smithy4s-cli. However, recently we did some small refactoring that moved some of the shapes from the top namespace that was excluded (e.g. a.b) into sub-namespaces (e.g. a.b.c and a.b.d).

This cause issues in the generated code as those nested namespaces were not excluded.

Would it be possible to allow excluding namespaces in a more convenient way? e.g. --exclude-ns a.b.* would exclude .a.b as well as any other namespace that starts with a.b

ghostbuster91 avatar Sep 17 '24 15:09 ghostbuster91

I'm all for it, if it's simple to implement then it shouldn't be a big deal to @Baccata either I assume

kubukoz avatar Sep 17 '24 22:09 kubukoz

PR away :)

Baccata avatar Sep 30 '24 08:09 Baccata

@baccata how flexible do you think this should be? Accept arbitrary regex, or just wildcards (if so, only trailing/leading or everywhere?)

kubukoz avatar Oct 22 '24 14:10 kubukoz

just wildcards (glob patterns) would be fine. Whatever you can find a concise implementation for.

Baccata avatar Oct 22 '24 18:10 Baccata

I can have a look into it. But first I would like to clarify the behavior. Going with glob patterns, it would mean that we have:

  • a.b.** - matches all namespaces below a.b (but not a.b itself)
  • a.b.*.d - matches only a single level on a namespace

Exact namespaces can be excluded with a.b and the combination of * and ** gives a lot flexibility in other scenarios.

But the a.b.* could be treated more like regex (in which case dots would have to be escaped internally to mean dot literals), which would mean that it matches all of the below:

  • a.b
  • a.b.c
  • a.b.c.d

Not sure which is more preferable here. I like the first solution more, as it feels more precise. But can be cumbersome too, if I want to exclude all the shapes from a.b and nested namespaces: I would have to include two patterns: a.b and a.b.**.

msosnicki avatar Feb 06 '25 14:02 msosnicki

IMO

  • a.b.* matches everything below a.b but not a.b itself
  • a.b* matches a.b and everything below

I don't think we have a need for * in the middle, it could be just a distraction at this point

so I guess I'm just proposing prefix-based exclusion/inclusion, with the special case of "no asterisk" which is an exact match

kubukoz avatar Feb 06 '25 15:02 kubukoz

Had a brief look, looks like alloy will also have to be involved https://github.com/disneystreaming/alloy/blob/6ac81f362362ea48165c07589021181e484f10ec/modules/openapi/src/alloy/openapi/package.scala#L33

I wonder why it only takes the allowedNS param, and the excludedNS is ignored in openapi context?

msosnicki avatar Feb 07 '25 12:02 msosnicki

No particular reason, probably just an oversight

Baccata avatar Feb 07 '25 14:02 Baccata