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

[v6] Naming fixes #625

Merged
merged 3 commits into from
Apr 28, 2020
Merged

[v6] Naming fixes #625

merged 3 commits into from
Apr 28, 2020

Conversation

joheredi
Copy link
Member

  • Add more reserved words
  • Provide more context info to normalizeName to get better prefixes when find a reserved name
  • Make sure to guard for reserved names when normalizing in Transforms
  • Use getOperationFullname function to avoid inconsistencies
  • Update generated files and tests

@joheredi joheredi requested review from daviwil and chradek April 23, 2020 23:31
src/transforms/operationTransforms.ts Outdated Show resolved Hide resolved
*/
export interface HeaderCustomNamedRequestIdParamGroupingHeaders {
export interface HeaderCustomnamedrequestidparamgroupingHeaders {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these are getting lowercased unexpectedly?

@@ -0,0 +1,434 @@
/*
* Copyright (c) Microsoft Corporation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like new files are being added for the renamed operation groups, you might need to delete the leftover files with the old name

@@ -4,7 +4,70 @@ import { Operation, OperationGroup } from "@azure-tools/codemodel";
import { getLanguageMetadata } from "./languageHelpers";
import { TypeDetails, PropertyKind } from "../models/modelDetails";

const ReservedModelNames = ["Error", "Date"];
const ReservedModelNames = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be using one set of rules for all models?

I can see one set of rules for things that can be 'new'd up. For example, OperationGroups can be instantiated directly by the user, so you need to guard against names like Date, String, etc.

However, properties can be pretty much anything. You can have an interface that looks like this:

interface Foo {
  string: string;
}

and that works just fine. Likewise for parameters:

function(string: string) {}

However, in the parameters case you definitely don't want to allow any reserved words (and that's probably true for properties too so that params/properties stay consistent across operation inputs and outputs.

Side-note: Can you make this list ordered alphabetically? It'll be easier to add things or check what's in it then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, thanks @daviwil and @chradek for your feedback around this. I agree with you and here's what I'm thinking:

  • Have metadata on the reserved words to indicate in which cases we want special handling. So that we just maintain a single list of reserved words but can choose case by case if we need to suffix the name.

  • File, operations and properties, don't need suffixing as @chradek mentioned above, so I have skipped a suffix in those cases.

  • OperationGroups, Parameters, Classes and Interfaces(for consistency) would need to be guarded against a subset of reserved words, such as Error, String, Date, Boolean, etc

    • OperationGroups will get Operations suffix.
    • Parameters would get Param suffix
    • Classes and Interfaces will get Model suffix

Copy link
Contributor

@daviwil daviwil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much improved, thanks a bunch of spending the extra effort on this!


const Newable = [NameType.Class, NameType.Interface, NameType.OperationGroup];

const ReservedModelNames: ReservedName[] = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this! Seems like all of them need NameType.Parameter so it feels like that should be checked by default in guardReservedNames, but I suppose it makes things less clear to not have it explicitly in the list.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about that. However by having it there we don't need any NameType specific checks in guardReservedNames and as you said makes it makes it clear and gives us flexibility in case we decide we don't want to suffix a specific reserved word. For instance string would be a valid parameter name

@joheredi joheredi merged commit 8ae3cd5 into Azure:v6 Apr 28, 2020
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

Successfully merging this pull request may close these issues.

3 participants