Мой ASP.NET Core API сериализует все мои классы в змеиный регистр при возврате ответов во внешний интерфейс. Я делал это в течение некоторого времени, но в последнее время мы используем API-интерфейс Graphql на серверной части и используем клубничный коктейль для создания классов и клиентов для взаимодействия с API-интерфейсом Graphql. Поскольку я повторно использую почти все API во внешнем интерфейсе нашего приложения (vuejs + typescript), я просто возвращаю эти классы, сгенерированные клубничным коктейлем, которые по умолчанию являются PascalCase в C #, но мой API снова преобразует их в змеиный регистр, что идеально, поэтому мой API единообразен для всех моих конечных точек и даже для тех, которые используют эти новые данные графа. Однако во внешнем интерфейсе мне нужно создать типы для использования этих новых данных Graphql и для упрощения работы. У меня есть файл Schema.json из API Graphql, который я преобразовал в типы машинописных текстов с помощью онлайн-инструмента. Опять же, все отлично, за исключением того, что этот файл Schema.json является верблюжьим, поэтому типы, которые он создает в этом инструменте, также являются верблюжьим. Поэтому мне нужно найти способ преобразовать этот гигантский список типов в змеиный регистр только для ключей (я предпочитаю сохранять сами классы в Pascal Case, как и мой внутренний API).
Есть ли простой способ сделать это. В качестве примера вот некоторые типы, которые мне нужно преобразовать, а это около 3000 строк кода:
export type Maybe = T | null
export type Exact = {
[K in keyof T]: T[K]
}
export type MakeOptional = Omit &
{ [SubKey in K]?: Maybe }
export type MakeMaybe = Omit &
{ [SubKey in K]: Maybe }
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: string
String: string
Boolean: boolean
Int: number
Float: number
/** A date string, such as 2007-12-03, compliant with the `full-date` format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar. */
Date: any
/** A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the `date-time` format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar. */
DateTime: any
}
export type Query = {
__typename?: "Query"
/**
* fetchCurrentUser returns user information for the currently logged in User
*
* If no user is currently logged in, the http request will return a 403 error, no graphQL body will be returned.
*/
fetchCurrentUser: User
/**
* fetchHealthPlanPackage returns a specific HealthPlanPackage by id
*
* If a package with the given ID cannot be found, this query returns undefined
* CMS users cannot fetch a DRAFT HealthPlanPackage
*
* Errors:
* - ForbiddenError:
* - A state user from a different state called this.
* - A CMSUser attempted to fetch a DRAFT HealthPlanPackage
*/
fetchHealthPlanPackage: FetchHealthPlanPackagePayload
/**
* indexHealthPlanPackages returns all of the HealthPlanPackages the current user can see.
*
* StateUsers can find all the packages for their state
* CMSUsers can find all the packages that do not have the DRAFT status
*/
indexHealthPlanPackages: IndexHealthPlanPackagesPayload
/**
* indexContracts returns all of the contracts the current user can see.
*
* StateUsers can find all the contracts for their state
* CMSUsers can find all the contracts that do not have the DRAFT status
*/
indexContracts: IndexContractsPayload
/**
* indexUsers returns all of the Users in the system.
*
* It can only be called by an AdminUser
*
* Errors: ForbiddenError: A non-AdminUser called this
*/
indexUsers: IndexUsersPayload
/**
* indexRates returns an array of rates with their revisions and related contracts
* Only rates with at least one submitted revision are returned
* indexRates can be called by CMS and admin users
*
* Errors:
* - ForbiddenError: User must be a CMS or Admin type user
* - NotFoundError: No rates with at least one submitted revision were found
*/
indexRates: IndexRatesPayload
/**
* fetchRate returns a rate with its revisions, including contract revisions
* for a given rate's ID
*
* It can be called by CMS or State users
*
* Errors:
* - ForbiddenError: This API is not available due to feature flags.
* - NotFoundError: rate for rate.ID not found in database
*/
fetchRate: FetchRatePayload
/**
* fetchContract returns a single contract, linked to revisions and related rates
* given a contractID
*
* It can be called by CMS or State users
*
* Errors:
* - ForbiddenError: A State user requests a contract that belongs to another state
* - NotFoundError: contract for contractID not found in database
*/
fetchContract: FetchContractPayload
/**
* fetchMcReviewSettings returns settings for the MC review app
*
* stateAssignments: List of all States in the system with their assigned CMS users.
*
* Errors:
* - ForbiddenError: A State user requests a contract that belongs to another state
*/
fetchMcReviewSettings: FetchMcReviewSettingsPayload
}
export type QueryFetchHealthPlanPackageArgs = {
input: FetchHealthPlanPackageInput
}
export type QueryIndexRatesArgs = {
input?: Maybe
}
export type QueryFetchRateArgs = {
input: FetchRateInput
}
export type QueryFetchContractArgs = {
input: FetchContractInput
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... ase-for-ke
Преобразование большого списка типов машинописных текстов из «верблюжьего» в «змеиный» только для ключей ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение