AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[enums](coding)

Martin Hope
Woodsy
Asked: 2025-04-11 22:27:59 +0800 CST

具有 $ref 的属性的 OpenAPI 子集

  • 6

我正在构建一个 schema A,它包含一个引用另一个 schema 的属性B。我遇到的问题是,我只需要 schema 中枚举属性的一个子集B。有没有办法在 yaml 文件中做到这一点?举个简单的例子,如果我正在为一家兽医办公室构建一些东西:

components:
  schemas:
    Dog:
      properties:
        color:
          description: Color of the dog
          $ref: "#/comonents/schema/color"
        injury:
          description: Information about the injury
          $ref: "#/comonents/schema/InjuryInfo"
    
    InjuryInfo:
      properties:
        location:
          description: where on the animal is the injury
          type: string
          enum: 
            - Body
            - Leg
            - Wing
        details:
          description: Additional Details
          type: string
        otherProperty:
          description: Some other property
          type: string

我需要重用该InjuryInfo架构,但我需要该Dog架构仅允许属性InjuryInfo.location和InjuryInfo.details。并且Dog.injury.location仅包含枚举值的子集。这可以从yaml文件中实现吗?

enums
  • 1 个回答
  • 20 Views
Martin Hope
pbickford
Asked: 2025-02-12 00:45:41 +0800 CST

MAUI 从 QueryProperty 读取枚举

  • 5

我有一个枚举:

 public enum MediaTypes
 {
     Book = 0,
     Video = 1,
     Magazine = 2,
     Picture = 3
     All = 99
 }

...我想将其传递给一个页面并将其值作为页面中的 QueryProperty 提取出来:

[QueryProperty("MediaType", "MediaType")]
public int MediaType { get; set; }

如果将类型设置为“int”,则此方法有效,但如果将类型设置为我真正想要的类型:MediaTypes,则会引发转换错误。

public MediaTypes MediaType { get; set; }

传递/解析枚举 QueryProperty 的正确方法是什么?

enums
  • 1 个回答
  • 22 Views
Martin Hope
Richard Hainsworth
Asked: 2024-07-25 20:48:08 +0800 CST

将 Str 列表转换为 Enums 列表

  • 7

我在模块中有一个枚举定义AAA:

enum RDProcDebug <None All AstBlock BlockType Scoping Templates MarkUp>;

class Debug {
  method foo(RDProcDebug @ds) {
    for @ds { say .key ~ ' => ' ~ .value }
  }
}

在 Raku 程序中,这种方法很有效,例如

use AAA;
my RDProcDebug $rp .= new;
$r.foo(AstBlock, BlockType);

但是现在我需要从命令行提供调试元素的名称,它只能提供 Str,例如

$ RDOpts='AstBlock BlockType' raku myprog

# and in myprog
if %*ENV<RDOpts>:exists {
  $rp.debug( %*ENV<RDOpts> ); # this does not work
}

那么如何将 Str 列表转换为枚举 RDProcDebug 类型的列表?

enums
  • 1 个回答
  • 22 Views
Martin Hope
Jordan
Asked: 2023-12-11 22:49:21 +0800 CST

带枚举的 Xsd - 输入枚举类型时出现错误

  • 5

我正在尝试添加枚举类型,如下所示。它添加了字符串类型,但当 jaxb 将 xsd 转换为 java 类时我需要枚举值。我使用 simpletype 将其转换为字符串,但不确定如何在元素内更改它,就像我尝试更改它一样,它会给我错误。

<xs:element name="DeletionReq">
    <xs:complexType>
        <xs:sequence>
                <xs:element name="Id" type="xs:long"/>
                <xs:element name="isNewProcess" type="xs:boolean" default="false"/>
                <xs:element name="data" type="tns:data" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:complexType name="data">
    <xs:sequence>
                      <xs:element name="dataColumnName" type="xs:string" minOccurs="0" />
                      <xs:element name="dataOldValue"   type="xs:string" minOccurs="0"/>
                      <xs:element name="dataNewValue"   type="xs:string" minOccurs="0"/>
                      <xs:element name="testRecord"   type="xs:string" minOccurs="0"/>
                      <xs:element name="projId"   type="xs:string" minOccurs="0"/>
                      <xs:element minOccurs="0" name="allowedApplDataColumnNames">
                          <xs:simpleType>
                            <xs:restriction base="xs:string">
                              <xs:enumeration value="code1" />
                              <xs:enumeration value="code2" />
                              <xs:enumeration value="code3" />
                              <xs:enumeration value="code4" />
                              <xs:enumeration value="code5" />
                            </xs:restriction>
                          </xs:simpleType>
                       </xs:element>
    </xs:sequence>
</xs:complexType>
enums
  • 2 个回答
  • 20 Views
Martin Hope
Alice
Asked: 2023-11-15 23:42:55 +0800 CST

Elixir 计算条件满足时出现的次数

  • 6

我尝试在 Elixir 中做以下可以在 Python 中实现的事情:

sum = 0
for elem in list:
  if elem >= 5:
    sum += 1

3例如:我想返回给定列表的数字[0, 5, 8, 3, 10]

这就是我在 Elixir 中所做的(这还不起作用):

    cond do
          Enum.empty?(list) -> 0
          length(list) == 1 -> if List.first(list) >= 5 do 1 else 0 end
          true -> 
            Enum.reduce(list, 0, fn x, acc -> if x >= 5 do acc + 1 end end)
          end
    end

我收到以下错误:** (ArithmeticError) bad argument in arithmetic expression: nil + 1

编辑:

找到了!问题是当 x < 5 时我没有返回任何值,导致没有值传递给acc因此accis nil。下面的代码有效:

cond do
      Enum.empty?(list) -> 0
      length(list) == 1 -> if List.first(list) >= 5 do 1 else 0 end
      true -> 
        Enum.reduce(list, 0, fn x, acc -> if x >= 5 do acc + 1 else acc + 0 end end)
      end
end
enums
  • 1 个回答
  • 29 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve