pierrejeambrun commented on code in PR #25123:
URL: https://github.com/apache/airflow/pull/25123#discussion_r923604481


##########
airflow/www/alias-rest-types.js:
##########
@@ -0,0 +1,185 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+const ts = require('typescript');
+const fs = require('fs');
+
+/* This library does three things to make openapi-typescript generation easier 
to use.
+ * 1. Creates capitalized exports for Paths and Operations
+ * 2. Alias Variables based either on the Path name or the Operation ID, such 
as:
+ *      export type ListProjectsVariables = 
operations['listProjects']['parameters']['query'];
+ * 3. Aliases the returned data types, such as:
+ *      export type ConnectionArgument = 
components['schemas']['ConnectionArgument'];
+ */
+
+/* Finds all words, capitalizes them, and removes all other characters. */
+const toPascalCase = (str) => (
+  (str.match(/[a-zA-Z0-9]+/g) || [])
+    .map((w) => `${w.charAt(0).toUpperCase()}${w.slice(1)}`)
+    .join('')
+);
+
+/* Adds a prefix to a type prop as necessary.
+ * ('', 'components') => 'components'
+ */
+const prefixPath = (rootPrefix, prop) => (rootPrefix ? 
`${rootPrefix}['${prop}']` : prop);
+
+// Recursively find child nodes by name.
+const findNode = (node, ...names) => {
+  if (!node || names.length === 0) return node;
+
+  const children = node.members || node.type.members;
+
+  if (!children) {
+    return undefined;
+  }
+
+  const child = children.find((c) => c.name?.text === names[0]);
+
+  return findNode(child, ...names.slice(1));
+};
+
+// Generate Variable Type Aliases for a given path or operation
+const generateVariableAliases = (node, operationPath, operationName) => {
+  const variableTypes = [];
+  const hasPath = !!findNode(node, 'parameters', 'path');
+  const hasQuery = !!findNode(node, 'parameters', 'query');
+  const hasBody = !!findNode(node, 'requestBody', 'content', 
'application/json');
+
+  if (hasPath) variableTypes.push(`${operationPath}['parameters']['path']`);
+  if (hasQuery) variableTypes.push(`${operationPath}['parameters']['query']`);
+  if (hasBody) 
variableTypes.push(`${operationPath}['requestBody']['content']['application/json']`);
+
+  if (variableTypes.length === 0) return '';
+  const typeName = `${toPascalCase(operationName)}Variables`;
+  return [typeName, `export type ${typeName} = ${variableTypes.join(' & ')};`];
+};
+
+// Generate Type Aliases
+// This is recurrsivenly called to generate types for Linege's external 
dependencies.

Review Comment:
   Typo `recurrsivenly`,  `Linege's` ? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to